/**
 * Javascript for Default Theme
 */
 /**
 * Theme
 *
 * for admin pages
 */
var Theme = {};

Theme.navigation = function() {
    $('ul.sf-menu').supersubs({
        minWidth:    12,                                // minimum width of sub-menus in em units
        maxWidth:    27,                                // maximum width of sub-menus in em units
        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over
    }).superfish({
        delay:       400,                               // delay on mouseout
        animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation
        speed:       'fast',                            // faster animation speed
        autoArrows:  false,                             // disable generation of arrow mark-up
        dropShadows: false                              // disable drop shadows
    });
}
/**
 * Forms
 *
 * @return void
 */
Theme.form = function() {
	$("form input[type=submit]").not('.filter input[type=submit]').addClass("ui-state-default ui-corner-all").hover(
		function(){
			$(this).addClass("ui-state-hover");
		},
		function(){
			$(this).removeClass("ui-state-hover");
		}
	)

	$("input[type=text][rel], select[rel]").not(":hidden").each(function() {
		var sd = $(this).attr('rel');
		$(this).after("<span class=\"description\">"+sd+"</span>");
	});
	$("textarea[rel]").not(":hidden").each(function() {
		var sd = $(this).attr('rel');
        if (sd != '') {
            $(this).after("<br /><span class=\"description nospace\">"+sd+"</span>");
        }
	});
}

/**
 * Rounded corners
 *
 * @return void
 */
Theme.roundedCorners = function() {
    $("table, .notice, .success, .error, input, select, textarea,h2.titulo,.node-type-directorio,.tags a").addClass('ui-corner-all');
}

Theme.externalLinks = function(){
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++){ 
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

/**
 * Document ready
 *
 * @return void
 */
$(document).ready(function() {
    Theme.navigation();
    Theme.form();
    Theme.roundedCorners();
    Theme.externalLinks();
});

