///////////////////////////// Window Onload///////////////////////////////

/*-------------------------- Auto Button ----------------------------*/
// Auto Button Rollovers for images with ".autobtn" class
var imgText;
$(".autobtn").each(function() {
	imgText = $(this).html();
	$(this).html("");
	$(this).append("<span class=\"btn-left\"></span>");
	$(this).append("<span class=\"btn-mid bold white large\">" + imgText + "</span>");
	$(this).append("<span class=\"btn-right\"></span>");
});

$(".autobtn").mouseover(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});

$(".autobtn").mouseout(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});

$(".autobtn-wide").each(function() {
	imgText = $(this).html();
	$(this).html("");
	$(this).append("<span class=\"btn-left\"></span>");
	$(this).append("<span class=\"btn-mid bold white large\">" + imgText + "</span>");
	$(this).append("<span class=\"btn-right\"></span>");
});

$(".autobtn-wide").mouseover(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});

$(".autobtn-wide").mouseout(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});

$(".autobtn-thin").each(function() {
	imgText = $(this).html();
	$(this).html("");
	$(this).append("<span class=\"btn-left\"></span>");
	$(this).append("<span class=\"btn-mid bold white large\">" + imgText + "</span>");
	$(this).append("<span class=\"btn-right\"></span>");
});

$(".autobtn-thin").mouseover(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});

$(".autobtn-thin").mouseout(function() {
	$(this).children(".btn-left").css("background-image","url()");
	$(this).children(".btn-mid").css("background-image","url()");
	$(this).children(".btn-right").css("background-image","url()");
});


// end Auto Button code


/*-------------------------- Activate Flippys ----------------------------*/

$("#secondary .flippy").not(".mini_lineup").setFlippy(155);
$("#secondary .home_page").setFlippy(213);
$("#secondary .mini_lineup").setFlippy(140);
$("#primary .advantages").setFlippy(160);
$("#primary .reviews").setFlippy(268);

/*-------------------------- Activate iTab -----------------------------*/

$(".itab > li > a").bind("click", function() {
	var target = $(this).parent();
	$(".itab li").addClass("itabby");
	if (target.attr("class").indexOf("active") == -1) {

		var itab_offset = $(".itabby").offset({ border: true, padding: true });
		if ($(window).scrollTop() > itab_offset.top) {
			$(window).scrollTop(itab_offset.top - 10);
		}
		
		$(".itab .active").removeClass("active");
		target.addClass("active");
		var thisUrl = $(this).attr("href");
		$(".itabscroll").slideTo(thisUrl);
		return false;		
	}
	return false;
});


$(".itab_options a.itab_prev").hover(function() {
	$(this).css("background", "url()").css("cursor","pointer");
}, function() {
	$(this).css("background", "url()").css("cursor","default");
});
$(".itab_options a.itab_next").hover(function() {
	$(this).css("background", "url()").css("cursor","pointer");
}, function() {
	$(this).css("background", "url()").css("cursor","default");
});

$(".itab_prev").bind("click", function() {
	var target = $(".itab .active").prev("li").children("a");
	if (target.attr("href"))	target.click();
	else	$(".itab li:last").children("a").click();
});
$(".itab_next").bind("click", function() {
	var target = $(".itab .active").next("li").children("a");
	if (target.attr("href"))	target.click();
	else	$(".itab li:first").children("a").click();
});


/*-------------------------- Toggly Functionality ----------------------------*/
$(".toggly dd").hide();
$(".toggly dd").after("<br />");
$(".toggly dt").toggle(function() {
	var toggle_class = $(".toggly").attr("class");
	if (toggle_class.indexOf("single")>0) {
		if ($(this).parent("dl").parent("div")) {
			$(this).parent("dl").parent("div").find("dt.on").click();
		} else {
			$(".toggly dt.on").click();
		}
	}
	$(this).next("dd").slideDown("fast");
	$(this).addClass("on");
}, function() {
	$(this).next("dd").slideUp("fast");
	$(this).removeClass("on");
});

$(".toggly_expand").click(function() {
	$(".toggly dt").each(function() {
		if ($(this).attr("class") != "on") {
			$(this).click();
		}
	});
});

$(".toggly_collapse").click(function() {
	$(".toggly dt").each(function() {
		if ($(this).attr("class") == "on") {
			$(this).click();
		}
	});
});

/*--------------------- old button rollover functionality ---------------------*/
$(".rollover").mouseover(function(){
	var imgUrl = $(this).attr("src");
	var imgUrlString = /\.jpg|\.jpeg|\.png|\.gif/g;
	var imgUrlType = imgUrl.match(imgUrlString);
	var imgFileParts = imgUrl.split(imgUrlType);
	$(this).attr("src",imgFileParts[0] + "_hover" + imgUrlType);
});

$(".rollover").mouseout(function(){
	var imgUrl = $(this).attr("src");
	if (imgUrl.indexOf("_hover")>0) {
		var imgFileParts = imgUrl.split("_hover");
		$(this).attr("src",imgFileParts[0] + imgFileParts[1]);
	}
});	

/*-------------------------- Reset Slidey  ----------------------------*/

setInterval("resetSlidey()",3000);

/*------------------------------ PNG Fix  ------------------------------*/

$("a[href*=.png]").css("behavior", "url(/js/iepngfix.htc)");
$("img[src*=.png]").css("behavior", "url(/js/iepngfix.htc)");

$("div,p,a,span").each(function() {
	if ($(this).css("background")) {
		var bgimg = $(this).css("background");
		if (bgimg.indexOf(".png")>0) {
			$(this).css("behavior", "url(/js/iepngfix.htc)");
		}
	}
});


/*------------------------- Anchor AutoLaunch  -------------------------*/

var thisUrl = location.href;
var thisUrlAnchor = thisUrl.split("#go_");
if (thisUrlAnchor[1]) {
	window.scrollTo(0,0);
	$("a[href*=#"+thisUrlAnchor[1]+"]").click();
}	
var thisUrlAnchor = thisUrl.split("#pop_");
if (thisUrlAnchor[1]) {
	$("a[class*="+thisUrlAnchor[1]+"]").click();
}	


/*---------------------------- Shadow Pop ----------------------------*/



/*------------------------------ Poppy Box  ------------------------------*/
$(".poppy, .thickbox").popIt();
