var numberOfSlides;
var interval;
$(document).ready(function(){
	$("#bottom ul:last").css("border", "none");

	$("table.striped tr:even").addClass("stripe");

	/* Dropdown Menu */
	$("#header .menu > li").hover(function(){
		$(this).find("ul").stop(true, true).show("fast");
		$(this).css("border-color", $(this).attr("rel"));
		
	}, function(){
		$(this).find("ul").stop(true, true).hide();
		$(this).css("border-color", "silver");
	});
	$("#header .menu li ul li a").hover(function(){
		$(this).css("color", $(this).parent().parent().parent().attr("rel"));
	}, function(){
		$(this).css("color", "#333333");
	});
	$("#header .menu a").hover(function(){
		$(this).css("color", $(this).parent().attr("rel"));
	}, function(){
		$(this).css("color", "#333333");
	});
	
	$("#header .search input[type=text]").click(function(){
		$(this).val("");
	});
	
	$(".htmlBanner a, .htmlBanner iframe").live("click", function(){
		var bannerId = $(this).closest(".htmlBanner").attr("rel");
		$.ajax({
			url: "inc/ajax.php", 
			type: "POST",
			data: { action: 'trackBannerClick', id: bannerId },
			async: false
		});
	});
	
	
	/* Featured Showcase Fader */
	numberOfSlides = $("#showcase .featured").length;
	interval = setInterval("next()", 4500);
		
	$("#overlay").css("opacity", "0.7").click(function(){
		closeWindow();
	});
	
	$(".redButton").each(function(){
		var contents = $(this).html();
		$(this).html("<span>" + contents + "</span>");
		$(this).prepend("<img src='images/redButtonLeft.gif' />").append("<img src='images/redButtonRight.gif' />");
	});
	
});

function loadWindow(id) {
	$("#popupWindow").show().find(".inner").html("<div style='text-align: center'><img src='images/ajax-loader.gif'>&nbsp;&nbsp;Loading...</div>").load("/popups/" + id + ".php", function(){
		
	});
	$("#overlay").show();
}
function closeWindow() {
	$("#popupWindow, #overlay").hide();
}

function next() {
	clearInterval(interval);
	$("#showcase *").stop(true, true);
	var $actualSlide = $("#showcase .featured:visible");
	var actualSlideNumber = $actualSlide.attr("rel");
	var nextSlideNumber = actualSlideNumber * 1 + 1;
	if (nextSlideNumber > numberOfSlides) nextSlideNumber = 1;
	var $nextSlide = $("#showcase .featured[rel=" + nextSlideNumber  + "]");
	$actualSlide.fadeOut(700);
	$nextSlide.fadeIn(700);
	interval = setInterval("next()", 4500);
}

function prev() {
	clearInterval(interval);
	$("#showcase *").stop(true, true);
	var $actualSlide = $("#showcase .featured:visible");
	var actualSlideNumber = $actualSlide.attr("rel");
	var nextSlideNumber = actualSlideNumber * 1 - 1;
	if (nextSlideNumber == 0) nextSlideNumber = numberOfSlides;
	var $nextSlide = $("#showcase .featured[rel=" + nextSlideNumber  + "]");
	$actualSlide.fadeOut(700);
	$nextSlide.fadeIn(700);
	interval = setInterval("next()", 4500);
}

function pause() {
	clearInterval(interval);
	$(".buttons .pause").css("cssText", "background-position: 0 15px!important").attr("href", "javascript:start()").attr("class", "start");
}

function start() {
	interval = setInterval("next()", 4500);
	$(".buttons .start").css("cssText", "background-position: 0 -34px!important").attr("href", "javascript:pause()").attr("class", "pause");
}
