//Banner rotate
var arrBanners = new Array();
var intBannerCount = 0;
var intCurBanner = 0;
var itvBannerRotate = 0;
var intBannerSpeed = 4000;
var boolAdmin = false;

function rotateBanner() {
	intTempBanner = intCurBanner + 1;
	if ($(".rotateHome > div:eq(" + intTempBanner + ")").length <= 0) {
		intTempBanner = 0;
	}
    $(".rotateHome > div:eq(" + intCurBanner + ")").hide();
    $(".rotateHome > div:eq(" + intTempBanner + ")").fadeIn("fast");
	intCurBanner = intTempBanner;
}

$(document).ready(function () {
    if (($(".rotateHome > div").length > 1) && ($("input[value='EDIT']:checked").length <= 0)) {

        $(".rotateHome > div").each(function () {
            $(this).hide();
            intBannerCount++;
        });
        $(".rotateHome > div:first").fadeIn("slow");
        itvBannerRotate = setInterval(rotateBanner, intBannerSpeed);
    }
	
	if (typeof(window['PFjQuery']) == "undefined") {
		$(".colorbox").colorbox({ iframe: true, innerWidth: 854, innerHeight: 480 });
	}

    $('#printlink').click(function () {
        window.print();
        return false;
    });
	
	$(".search .text-field").focus(function (srcc) {
		if ($(this).val() == $(this)[0].title) {
			$(this).removeClass("defaultTextActive");
			$(this).val("");
		}
	});

	$(".search .text-field").blur(function () {
		if ($(this).val() == "") {
			$(this).addClass("defaultTextActive");
			$(this).val($(this)[0].title);
		}
	});

	$(".search .text-field").blur();
	
/*	$('a[href^="http"]').each(
		function(){
		  if(this.href.indexOf(location.hostname) == -1) {
			$(this).attr({
				target: "_blank", 
				title: "Opens in a new window"
			  })
			  .append(' *');
		  }
		}
	  )
*/
		$("a[href^='http']").not(".vidWrapper a").not(".collapse-content a").not("#nav a").not("#subLeft a").each(function() {
			if ($("#cbexternallinkconfirm").length < 1) {
				var strDisclaimer = 'You are leaving a <b>Baxter</b> website. <b>Baxter</b> takes no responsibility for, and exercises no control over the contents, link accuracy, accessibility and reliability of the linked websites and does not necessarily endorse the views expressed with them. Users cannot assume that the external websites will abide by the same Privacy Policy to which <b>Baxter</b> adheres. <b>Baxter</b> is providing these links to you only as a convenience.';
				var strDiv = '<div id="cbexternallinkconfirm"><h5>You are now leaving LiveNow.info</h5>';
				strDiv += '<p>' + strDisclaimer + '</p>';
				strDiv += '<div class="cbconfirmbuttons"><a href="#" class="cbexternal-continue">Continue</a><a href="#" class="cbexternal-return">Return to LiveNow.info</a></div></div>';
				$("body").append(strDiv);
				$("#cbexternallinkconfirm .cbexternal-continue").click(function(event) {
					event.preventDefault();
					window.open($("#cbexternallinkconfirm").data("exturl"));
					$.colorbox.close();
				});
				$("#cbexternallinkconfirm .cbexternal-return").click(function(event) {
					event.preventDefault();
					$.colorbox.close();
				});
			}
			if (this.href.indexOf(location.hostname) == -1) {
				$(this).attr({
					target: "_blank"
					}).click(function(event) {
					$("#cbexternallinkconfirm").data("exturl",this.href);
					event.preventDefault();
					$(this).colorbox({inline:true, href:"#cbexternallinkconfirm", innerWidth: "500px", innerHeight: "280px"});
				});
			}
		});
    if ($(".carousel-side .vidCarousel ul li").length != null) {
        if ($(".carousel-side .vidCarousel ul li").length < 5) {
            $(".carousel-side .vidPrev").hide();
            $(".carousel-side .vidNext").hide();
        }
    }

    $('#subBread > a:first-child').css('color', '#666666');
    $('#subBread > span > a:last-child').css('fontWeight', 'bold');
    $('#subBread > span > a:last-child').css('color', '#ff6633');

    if ($(".collapse-wrap").length > 0) {
        $(".collapse-wrap .title").click(function () {
            if ($(this).parent().find(".collapse-content").css("display") != "block") {
                $(this).addClass("collapse-expanded");
                $(this).parent().find(".collapse-content").slideDown("fast");
            } else {
                $(this).removeClass("collapse-expanded");
                $(this).parent().find(".collapse-content").slideUp("fast");
            }
        });
    }
    if ($(".collapse-wrap").length > 1) {
        //$(".collapse-wrap:first").prepend("<p><a href=\"javascript:void(0);\" class=\"collapsible-collapse-all\">Collapse All</a> | <a href=\"javascript:void(0);\" class=\"collapsible-expand-all\">Expand All</a></p>");
        $(".collapsible-collapse-all").click(function () {
            expandAll('collapse');
        });
        $(".collapsible-expand-all").click(function () {
            expandAll('expand');
        });
    }

    return false;
});
// expand/collapse all collapsible content
function expandAll(strMode) {
	if (strMode == "expand") {
		$(".collapse-wrap .title").each(function() {
			$(this).addClass("collapse-expanded");
			$(this).parent().find(".collapse-content").slideDown("fast");																	 
		});
	} else {
		$(".collapse-wrap .title").each(function() {
			$(this).removeClass("collapse-expanded");
			$(this).parent().find(".collapse-content").slideUp("fast");															 
		});
	}
}

//Suckerfish
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
