var z=9;
var over="";
var img_counter=0;
var img_counter2=0;
var timer;
var delay=6000;
$(document).ready(function() {
	var max_counter=$("#about_mainimagecontainter li").length;
	$(".holder").css({"opacity" : 0.0});
	$("#about_holder").css({"opacity" : 1.0});
	$("#about").css({"background-position": "0px -160px"});
	if ($.client.os==="Mac") {
		$(".hover_menu").css({"margin-left":"-2px"});
	}
	
	$(".location_link").click(function(event) {
		event.preventDefault();
		$(".contact_containter").css({"display":"none"});
		$("#"+$(this).attr("href")).css({"display":"block"});
	});
	
	$(".holder").live("click", function() {
		if ($(this).hasClass("video")) {
			
		}
		else {
			window.location=$(this).attr("href");
		}
	});
			
	$(".index_subnavigationitem").hover(function() {
		$(".index_subnavigationitem").css({"background-position": "0px 0px"});
		$(this).css({"background-position": "0px -160px"});
		var holder="#"+$(this).attr("id")+"_holder";
		z++;
		$(holder).css({"z-index":z}).animate({"opacity":1.0}, function() {
			$(".holder").css({"opacity" : 0.0});
			$(this).css({"opacity" : 1.0});
		});
	}, function() {
		$(this).css({"background-position": "0px -160px"});
	});
	$(".menu_item").hover(function() {
		$("#"+$(this).attr("id")+"_menu").css({display:"block"});
		$(this).css({"background":"url(images/blackpng.png)"});
	}, function() {
		$("#"+$(this).attr("id")+"_menu").css({display:"none"});
		$(this).css({"background":"none"});
	});
	$(".hover_menu").hover(function() {
		$(this).css({display:"block"});
		$("#"+$(this).attr("id").replace("_menu", "")).css({"background":"url(images/blackpng.png)"});
	}, function() {
		$(this).css({display:"none"});
		$("#"+$(this).attr("id").replace("_menu", "")).css({"background":"none"});
	});
	
	$(".about_selector").live("click", function() {
		clearTimeout(timer);
		var pos=$(this).attr("id").replace("scroller","");
		$("#about_mainimagecontainter").animate({"left":"-"+(pos*917)+"px"}, function() {
			img_counter=pos;
			$(".about_selector").removeClass("first");
			$("#scroller"+img_counter).addClass("first");
			timer=setTimeout(function(){scrollAbout()},delay);	
		});
	});
	
	$("#about_mainimagecontainter").css({"width":($("#about_mainimagecontainter li").length+1)*917+"px"});
	$(".first").css({backgroundPosition:"0px -14px"});
	timer=setTimeout(function(){scrollAbout()},delay);
	
	$('#scroller li').each(function(index) {
		if ($("#about_selector_nav").length==0) {
			$("#about_mainimage").append('<div id="about_selector_nav"><div class="about_selector first" id="scroller'+img_counter2+'"></div></div>');
		}
		else {
			$("#about_selector_nav").append('<div class="about_selector" id="scroller'+img_counter2+'"></div>');
		}
		img_counter2++;
	});
	
	$(".social").hover(function() {
		$(this).css({"backgroundPosition":"0 -27px"});
	}, function() {
		$(this).css({"backgroundPosition":"0 -0"});
	});
	
	$("#scroller").children(":first").clone().appendTo($("#scroller"));
	
	function scrollAbout() {
		$("#about_mainimagecontainter").animate({"left":$("#about_mainimagecontainter").css("left").replace("px","")-917+"px"}, function() {
			img_counter++;
			if (img_counter==max_counter) {
				$("#about_mainimagecontainter").css({"left":"0px"});
				img_counter=0;
			}
			$(".about_selector").removeClass("first");
			$("#scroller"+img_counter).addClass("first");
			timer=setTimeout(function(){scrollAbout()},delay);
		});
	}
});
