//On Hover Over
function megaHoverOver() {
    $(".wrapperheader").animate({
        'padding-top': "88px"
    }, 100)
    $(".wrapperheaderclean").animate({
        'padding-top': "102px"
    }, 100)
    $(this).find(".sub").stop().slideDown('fast').show(); //Find sub and fade it in
    (function ($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function () {
            rowWidth = 2;
            //Calculate row
            $(this).find("ul").each(function () { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery);

    if ($(this).find(".row").length > 0) { //If row exists...

        var biggestRow = 0;

        $(this).find(".row").each(function () {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if (rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({ 'width': biggestRow }); //Set width
        $(this).find(".row:last").css({ 'margin': '0' });  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({ 'width': rowWidth }); //Set Width

    }

    //$(".wrapperheader").css('padding-top', '88px');

}
//On Hover Out
function megaHoverOut() {
    $(this).find(".sub").stop().slideUp('fast', function () { //Fade to 0 opactiy
        $(this).hide();  //after fading, hide it
        $(".wrapperheader").animate({
            'padding-top': "0"
        }, 100)
        $(".wrapperheaderclean").animate({
            'padding-top': "0px"
        }, 100)
        //$(".wrapperheader").css('padding-top', 0);
    });
}

$(document).ready(function () {
    //Set custom configurations
    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
        interval: 100, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 500, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    try {
        $("nav ul li .sub").css({ 'opacity': '1' }); //Fade sub nav to 0 opacity on default
        $("nav ul li.consubmenu").hoverIntent(config); //Trigger Hover intent with custom configurations  
    }
    catch (err) {
        //Handle errors here
    }




});


//***************************** Menu *****************************//

function mainmenu() {
    jQuery("#nav ul li a").removeAttr("title");
    jQuery("#nav ul a").removeAttr("title");
    jQuery("#nav ul ul ").css({ display: "none" }); // Opera Fix
    jQuery("#nav ul li").hover(function () {
        jQuery(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function () {
        jQuery(this).find('ul:first').css({ visibility: "hidden" });
    });
}

jQuery(document).ready(function () {
    mainmenu();
});


//***************************** Lightbox *****************************//

/*
jQuery(document).ready(function(){

jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");
	
jQuery("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'facebook'
});

});
*/


//***************************** Tabs *****************************//

/*
jQuery(document).ready(function(){
var panelContainer = jQuery('div#panels');
jQuery('<div id="tabs"></div>').insertBefore(panelContainer);	
panelContainer.find('div.panel').each(function(n){
jQuery('div#tabs').append('<a class="tab" href="#' + (n+1) + '">' + jQuery(this).attr('title') + '</a>');
});
var panelLocation = location.hash.slice(1);
if(panelLocation){
var panelNum = panelLocation;
}else{
var panelNum = '1';
}
panelContainer.find('div.panel').hide();
panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
jQuery('div#tabs').find('a.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
jQuery('div#tabs').find('a').each(function(n){
jQuery(this).click(function(){
panelContainer.find('div.panel').hide();
panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
jQuery(this).parent().find('a').removeClass().addClass('tab');
jQuery(this).removeClass().addClass('tab-active');
});
});
});
*/


//***************************** Scrollable Content *****************************//

jQuery(document).ready(function () {

    jQuery("#scrollslider").smoothDivScroll({
        scrollInterval: 16,
        mouseDownSpeedBooster: 1,
        autoScrollDirection: "endlessloopright",
        autoScrollSpeed: 2,
        visibleHotSpots: "always"
    });

    jQuery("#scrollportfolio").smoothDivScroll({
        scrollInterval: 16,
        mouseDownSpeedBooster: 1,
        autoScrollDirection: "endlessloopright",
        autoScrollSpeed: 2,
        visibleHotSpots: "always"
    });

});


//***************************** Image Hover Effect *****************************//


jQuery(document).ready(function () {
    jQuery('.slider-thumbnail .meta, .portfolio-thumbnail .meta').css({ 'opacity': '0' });
    jQuery('.slider-thumbnail, .portfolio-thumbnail').hover(
		function () {
		    jQuery(this).find('.meta').stop().fadeTo(500, 0.8);
		},
		function () {
		    jQuery(this).find('.meta').stop().fadeTo(500, 0);
		}
	)
});


//***************************** Thumbnail Slide Up Effect *****************************//

jQuery(document).ready(function () {

    // Slider Captions
    jQuery(".slider-large").hover(function () {
        jQuery(this).find(".caption").animate({ top: "-525px" }, { queue: false, duration: 500 });
    },
		function () {
		    jQuery(".caption").animate({ top: "-650px" }, { queue: false, duration: 500 });
		});

    /*jQuery(".slider-medium").hover(function(){
    jQuery(this).find(".caption").animate({top:"-350px"},{queue:false,duration:500});},
    function(){ jQuery(".caption").animate({top:"-475px"},{queue:false,duration:500});
    });*/

    jQuery(".slider-small").hover(function () {
        jQuery(this).find(".caption").animate({ top: "-418px" }, { queue: false, duration: 500 });
    },
		function () {
		    jQuery(".caption").animate({ top: "-553px" }, { queue: false, duration: 500 });
		});

    // Slider Thumbnails
    jQuery("#slider-container").hover(function () { jQuery(this).find("#slider-thumbnails-wrapper").animate({ top: "-100px" }, { queue: false, duration: 500 }); },
		function () {
		    jQuery("#slider-thumbnails-wrapper").animate({ top: "0px" }, { queue: false, duration: 500 });
		});
    jQuery("#slider-container.slider-small").hover(function () { jQuery(this).find("#slider-thumbnails-wrapper").animate({ top: "-150px" }, { queue: false, duration: 500 }); },
		function () {
		    jQuery("#slider-thumbnails-wrapper").animate({ top: "25px" }, { queue: false, duration: 500 });
		});

});


/*************************** Play/Pause Slider ***************************/


jQuery(document).ready(function () {

    // Toggle Slider Controls
    jQuery(".rotation").toggle(
		function () {
		    jQuery('#slider').cycle('pause');
		    jQuery(".rotation-button").replaceWith('<span class="rotation-button">&#9658;</span>');
		},
		function () {
		    jQuery('#slider').cycle('resume');
		    jQuery(".rotation-button").replaceWith('<span class="rotation-button pause-button">&#x2590;&#x2590;</span>');
		}
	);

    // Pause Slider When Videos Clicked
    jQuery(".pause").click(function () {
        jQuery('#slider').cycle('pause');
    });

});

/*************************** Image Preloader ***************************/

jQuery(function () {
    jQuery('.preload').hide();
});

var i = 0;
var inte = 0;
jQuery(window).bind("load", function () {
    var inte = setInterval("doThis(i)", 50);
});

function doThis() {
    var images = jQuery('.preload').length;
    if (i >= images) {
        clearInterval(inte);
    }
    jQuery('.preload:hidden').eq(0).fadeIn(500);
}


/*************************** Contact Form ***************************/

jQuery(document).ready(function () {

    jQuery('#contact-form').submit(function () {

        jQuery('.contact-error').remove();
        var hasError = false;
        jQuery('.requiredFieldContact').each(function () {
            if (jQuery.trim(jQuery(this).val()) == '') {
                jQuery(this).addClass('input-error');
                hasError = true;
            } else if (jQuery(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if (!emailReg.test(jQuery.trim(jQuery(this).val()))) {
                    jQuery(this).addClass('input-error');
                    hasError = true;
                }
            }
        });

    });

    jQuery('#contact-form .contact-submit').click(function () {
        jQuery('.loader').css({ display: "block" });
    });

});


/*************************** Theme Options Panel ***************************/

jQuery(document).ready(function () {
    jQuery(".trigger").click(function () {
        jQuery(".theme-box").toggle("fast");
        jQuery(this).toggleClass("active");
        return false;
    });
});

jQuery(document).ready(function () {

    Cufon.replace('#before-promos h3,#before-promos h2', { fontFamily: 'Utopia SC' });
    Cufon.replace('#main h3', { fontFamily: 'Utopia SC' });
    Cufon.replace('ul.tabs a', { fontFamily: 'Utopia SC' });
    Cufon.replace('nav ul li a', { fontFamily: 'Utopia SC' });
    Cufon.replace('.cufonh2', { fontFamily: 'Utopia SC' });
    Cufon.replace('.cufona', { fontFamily: 'Utopia SC' });
    Cufon.replace('.buscar h2', { fontFamily: 'Utopia SC' });
    Cufon.replace('time', { fontFamily: 'Hattori Hanzo' });
    //Cufon.replace('header nav ul li a',{ fontFamily: 'Times New Roman'} );

    Cufon.now();
});


/*           tabs           */

$(document).ready(function () {

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); Cufon.refresh(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function () {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        Cufon.refresh();
        return false;
    });

});
$(document).ready(function () {

    //When page loads...
    $(".tab_content2").hide(); //Hide all content
    $("ul.tabs2 li:first").addClass("active").show(); //Activate first tab
    $(".tab_content2:first").show(); Cufon.refresh(); //Show first tab content

    //On Click Event
    $("ul.tabs2 li").click(function () {

        $("ul.tabs2 li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content2").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        Cufon.refresh();
        return false;
    });

});


//***************************** FancyBox *****************************//

function fancy() {
    $("a[rel^='fancybox']").fancybox({
        'width': 528,
        'height': 308,
        'padding': 0,
        'margin': 0,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });
}

jQuery(document).ready(function () {
    $("a[rel^='fancybox']").fancybox({
        'width': 528,
        'height': 308,
        'padding': 0,
        'margin': 0,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });

    $("a[rel^='fancyboximg']").fancybox({

        'padding': 0,
        'margin': 0,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none'
    });

    $("a[rel^='fancyboxaviso']").fancybox({
        'width': 610,
        'height': 420,
        'padding': 0,
        'margin': 0,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'showNavArrows':false
    });
});


function buscador() {

}


$(document).ready(function () {
    $('.buscador').live('submit', function () {
        //alert($('#orden').val());
        if ($('#ordenselect').length > 0) {
            var input = $("<input>").attr("type", "hidden").attr("name", "orden").val($('#ordenselect').val());
            $('.buscador').append($(input));
        }
        else {
            var inputstr = $("<input>").attr("type", "hidden").attr("name", "orden").val("0");
            $('.buscador').append($(inputstr));
        }
        return true;
    });
    if ($('#ordenselect').length > 0) {
        $('#ordenselect').change(function () {
            $('.buscador').submit();
        });
    }
});

