jQuery.fn.fadeToggle = function(speed, easing, callback) {

    return this.animate({opacity: 'toggle'}, speed, easing, callback);

};



var curr=0;

var max=3;

var next = true;

var windowTimer;

var windowTimerTimeout = 4000;

var currTag = "";

var currentLeftNav;



function switchTimer(i, scroll){

	scroll = (typeof scroll=="undefined") ? true : scroll;

	curr = (i<0) ? max-1 : i;

	curr = (curr==max) ? 0 : curr;

	next = (!next || i==max) ? false : curr+1;

	var ul = $("#rotator-entries");

    $("#rotator-entries li:eq(" + (curr) +")").addClass("active").siblings().removeClass("active");

    $("#rotator-controls li:eq(" + (curr) +")").addClass("active").siblings().removeClass("active");

	if(scroll){

	    clearTimeout(windowTimer);

        windowTimer = setTimeout("switchTimer(" + (curr+1) + ")",windowTimerTimeout);

	}

}



function initNav(){

    $("#primary-nav ul li.sub").hover(function(){ if($.browser.msie && $.browser.version<=7){ie_apply_zindex($(this).find("div.sub_nav")); } $(this).addClass("hover"); },function(){ $(this).removeClass("hover");});

}

function initLeftNav(){

    currentLeftNav = $("#left-nav ul li.active");

    if(!currentLeftNav.length){

        var head = $("#top h2").text();

        if(head=="10 Sensitive Skin Dos and Don'ts"){

            currentLeftNav = $("#left-nav ul li:eq(1)").addClass("active");

        } else if(head=="The Importance of Barrier Protection") {

            currentLeftNav = $("#left-nav ul li:eq(2)").addClass("active");

        } else if(head=="Undereye Puffiness and Dark Circles") {

            currentLeftNav = $("#left-nav ul li:eq(4)").addClass("active");

        } else if(head=="What is Eczema") {

            currentLeftNav = $("#left-nav ul li:eq(7)").addClass("active");

        }

    }

    $("#left-nav ul li").hover(function(){ $(this).addClass("active").siblings().removeClass("active"); },function(){ $(this).removeClass("active");currentLeftNav.addClass("active");});

}

function loadUtils(){

    $("#fb-like").attr("src",'http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(document.location.href.replace(/\/index\d*\.html/,'/').replace(/\?.*$/,'').replace(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/,'firstaidbeauty.com')) + "&locale=en_US&layout=button_count&show_faces=false&width=90&action=like&colorscheme=light&height=21");

    //$("#fb-like").attr("src",'http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(document.location.href) + "&locale=en_US&layout=button_count&show_faces=false&width=90&action=like&colorscheme=light&height=21");

}

function initRotators(){

	clearTimeout(windowTimer);

	curr=0;

	windowTimer = setTimeout("switchTimer(" + (curr+1) + ")",windowTimerTimeout);

	$("#rotator-controls").click(function(e){

	    var curr_tag = e.target ? e.target : e.srcElement;

		if(curr_tag.tagName != "LI") return;



		var num = parseInt(curr_tag.id.substring(4));

		switch(curr_tag.className){

			case "active": return;

			default: switchTimer(num-1,true);

			         break;

		}

	});

}



function getProductType(index) {

	for(i=1; i<=4; i++) {

		var t= document.getElementById('product_tab'+i);

		var l= document.getElementById('link_tab'+i);

		if(t) {

			if(i == index) {

				t.style.display = '';

				if(l) l.className = "act";

			} else {

				t.style.display = 'none';

				if(l) l.className = "";

			}

		}

	}

	return false;

}



$(function(){

    $("body.press #top ul").each(function(i){

        var numChild = $(this).children().length;

        var childHeight = $(this).children(":last").height()+1;

        childHeight = 258;

        if((numChild % 4) != 0){

            for(var i=4-(numChild%4); i>0; i--){

                var item = $("<li>").attr("style","height:"+childHeight+"px;").addClass("right");

                //$(this).append(item);

            }

        }

    });



    $("body.faq #top p b").click(function(){

	$(this).next().toggle();

    });



    if($("body").hasClass("product-inner") || $("body").hasClass("press") || $("body").hasClass("cart")){

	$("body.product-inner a[auZoom=true], body.press a[auZoom=true], body.cart a[auZoom=true]").fancybox({

		overlayOpacity: 0.9,

		overlayColor: "#fff",

		scrolling: "no",

		titleShow: false

	});

	}

});



/* IE6 Z-Index Fix!!! */

var iaz_preserved_elements = [];

var iaz_preserved_zindexes = [];

function ie_apply_zindex(element_id, zindex, context_id) {

   // default values

   if (undefined == zindex) { zindex = 1; }

   var context = (undefined == context_id) ? $(context_id) : $("body");

   var element = $(element_id);



   for (i = iaz_preserved_elements.length-1; i >= 0; i--) {

      iaz_preserved_elements[i].css({'z-index': iaz_preserved_zindexes[i]});

   }

   iaz_preserved_elements = [];

   iaz_preserved_zindexes = [];





   // find relative-positioned ancestors of element within context

   element.parents().each(

      function(ancestor) {

         if ('relative' == $(this).css('position')) {

            // apply z-index to ancestor

			iaz_preserved_elements.push($(this));

			iaz_preserved_zindexes.push( $(this).css('z-index') );



 			$(this).css({'z-index': zindex});

         }

         if ($(this) == context) { throw $break; }

      }

   );

}


