var $s = jQuery.noConflict();
$s(document).ready(function($) {  
	$('a[rel*=facebox]').facebox();

    // open a link in a new window, this is valid target="_blank" is not.
    $('a.blank').click(function(){ 
        window.open(this.href);
        return false;
    }) 
 
	//Fix for Firefox
	$('button.button').hover(function(){
		$(this).children("span").children("span").addClass("hover");
	}, function(){
		$(this).children("span").children("span").removeClass("hover");
	});
	
	$.fn.workUp = function(){
		$(this).live('mouseenter mouseleave', function(event) {
		  var panel = $('.detail-wrap', $(this));
		  if (event.type == 'mouseenter') {
			panel.animate({top: '35px'}, 500, 'swing');
			console.log("mouseenter");
		  } else {
			panel.animate({top: '187px'}, 500, 'swing')
			console.log("mouseout");
		  }
		});
	}
	$(".block-related .mini-products-list li").workUp();
	
	jQuery('.block-related .mini-products-list.large').jcarousel({
		scroll: 1,
		visible:4	 
	});	
	
	/*if($(".optionsWrapper").html() == false) {
		var contents = "<div class='product-options jqtransformdone' id='product-options-wrapper'>"+$(".product-options").html()+"</div>";
		contents += $(".product-options").next().html();
		contents += $(".product-options").next().next().html();
		$(".optionsWrapper").append(contents);
	}*/
	
	// this is for the flowplayer overlay
	$("body").append("<div class='overlay' id='overlay'><div class='contentWrap'></div></div>");
	var exposeConfig = {color: '#000',loadSpeed: 200,	opacity: 0.8 };

	$('.left-nav.brands .head.active').siblings().show();
	$('.left-nav.brands .head').click(function(){
		$(this).toggleClass("active");
		$(this).siblings().slideToggle();
	});
	//$('.block-layered-nav dl dt:first-child').addClass("active");
	//$('.block-layered-nav dl dd:nth-child(2)').show();
	$('.block-layered-nav dl dt.active').next().show();
	$('.block-layered-nav dl dt').click(function(){
		$(this).toggleClass("active");
		$(this).next().slideToggle();
	});
	
	
	$('label.in-field').inFieldLabels();
	$('a.account').click(function(){
		$(this).toggleClass("selected");
		$('.pulldown').slideToggle("fast");
		return false;
	});
	$('.pulldown .close').click(function(){
		$('.pulldown').slideToggle("fast");
		$('a.account').removeClass("selected", "slow");
		return false;
	});
	$('.block-cart .block-title').click(function(){ return false; });
	$('.block-cart').hover(function(){
		$(this).toggleClass("selected");
		$('.block-cart .block-content').slideToggle("fast");
	}, function(){
		$(this).toggleClass("selected");
		$('.block-cart .block-content').slideToggle("fast");
	});

	$('.newsletter').click(function() {
		$('#newsletter-dd').slideToggle('fast', function() {
	  });
	});
	
	if($("#gcheckout-shipping-method-available").length > 0){
		if($('input[name=shipping_method]:checked').length <= 0){
			$('input[name=shipping_method]:first').attr("checked", "checked");
		}else{
		}
	}

    //nav - on hover over
    function megaHoverOver() {
        $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
        (function ($) {
            //Function to calculate total width of all ul's
            jQuery.fn.calcSubWidth = function () {
                rowWidth = 0;
                //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

        }
    }
    //nav - on hover out
    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function () { //Fade to 0 opactiy
            $(this).hide();  //after fading, hide it
        });
    }
	if($(".lowerTabs").html() != null){
		if($(".lowerTabs .active").html() == null){
			$(".lowerTabs .product-tabs").children(":first-child").addClass("active");
			$(".lowerTabs .product-tabs-content").slice(1).attr("style", "display:none");
		}
	}

    // for dropdowns - set custom configurations
    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
        interval: 0, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 200, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

   $(".nav ul li .sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
   $(".nav ul li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
	$(".nav ul li .sub").hover(function(){		
		$(this).siblings("a").addClass("hover");
	}, function(){
		$(this).siblings("a").removeClass("hover");	
	});
	
	//$("input[type=radio]").addClass("jqTransformRadio");
	$('.account-create form').jqTransform({imgPath:'images/img/'});
	$('.shipping form').jqTransform({imgPath:'images/img/'});
	$('.login').jqTransform({imgPath:'images/img/'});
	$('.step form').jqTransform({imgPath:'images/img/'});
	//$('.my-account form').jqTransform({imgPath:'images/img/'});
	$('.product-options').jqTransform({imgPath:'images/img/'});
		$('.product-options .jqTransformSelectWrapper').css("z-index","10");
	$('.cart form').jqTransform({imgPath:'images/img/'});
	$('.customer-address-form form').jqTransform({imgPath:'images/img/'});
	$('.newsletter-manage-index form').jqTransform({imgPath:'images/img/'});
	$('#reorder-validate-detail').jqTransform({imgPath:'images/img/'});
	
	$(".checkout-onepage-index .jqTransformSelectWrapper ul").attr("style","height:150px; overflow-y:auto; overflow-x:auto; width:100%;");
	
	$('.anythingFader').anythingFader({
        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 4000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 500,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
        startText: "Go",                // Start text
        stopText: "Stop"               // Stop text
    });
	
	/*
	var email = $("#email").attr("value");
	//alert("email: "+email);
	var password = $("#pass").attr("value");
	if(email.length > 0 || password.length > 0){
		alert("before change");
		$("#email").change();
		$("#pass").change();
		alert("after change");
	}*/

}); 
//END (DOCUMENT).READY

