$(function() {
	//alert(viewport.height());
	adjust_theim_height();
	load_default_billboard();
	set_mask_height();
	set_nav_width();
	$(".th_mask").each(function(){
        $("#"+this.id).mouseover(function(){
        	//remove_active_classes();
        	$(".th_mask").removeClass("th_active");
        	$("#"+this.id).addClass("th_hover");
        	clearTimeout(t);
        }).mouseout(function(){
        	$("#"+this.id).removeClass("th_hover");
        	$("#"+this.id).addClass("th_active");
        }).click(function(){
			var raw_id = this.id.split("_");
if(raw_id=='th,0')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_0.jpg)";			
}
if(raw_id=='th,1')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_1.jpg)";			
}

if(raw_id=='th,2')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_2.jpg)";			
}
if(raw_id=='th,3')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_3.jpg)";			
}
       	show_billboard(raw_id[1]);
		});
	 });	
	t=setTimeout('startSlideShow(1)',8000);
});


function startSlideShow(n){
	var thn = $(".th_mask");
	var x = n;	
if(x=='0')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_0.jpg)";			
}
if(x=='1')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_1.jpg)";			
}

if(x=='2')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_2.jpg)";			
}

if(x=='3')
{
document.getElementById('homepanel').style.background ="url(/assets/look/images/bg_3.jpg)";			
}
	$(".th_mask").removeClass("th_active");
	$("#th_"+x).addClass("th_active");
    show_billboard(x);
    x++;
    if(x==thn.length){x=0}
    t=setTimeout('startSlideShow('+x+')',5000);
}
function load_default_billboard(){
	$("body#home").addClass("hero0");
	$("#home_hero_txt_0").show();
	$("#th_0").addClass("th_active");
}
function show_billboard(n){
	$(".home_hero_txt").hide();
	$("#home_hero_txt_"+n).show();
}
function adjust_theim_height(){
	if (viewport.height() > 960){
		$("#home_top").height(500);
	} else if (viewport.height() < 960 && viewport.height() > 768){
		$("#home_top").height(450);
	} else if (viewport.height() < 768){
		$("#home_top").height(400);
	}	
}

function set_mask_height(){
	if (viewport.height() < $("#container").height()){
		$("#mask").height($("#container").height());
	}else{
		$("#mask").height(viewport.height());
	}	
}
function set_nav_width(){
	var prim = $("#primary_nav").width();
	$("#secondary_nav").width(prim+10);
}
jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}
window.viewport = {
    height: function() {
        return $(window).height();
    },
    width: function() {
        return $(window).width();
    },
    scrollTop: function() {
        return $(window).scrollTop();
    },
    scrollLeft: function() {
        return $(window).scrollLeft();
    }
};

$(window).resize(function() {
  adjust_theim_height();
  set_mask_height();
});


