// JavaScript Document

if (document.images){
 pic1= new Image(191,1);
 pic1.src=site_url+"site/images/layout/bg-dropdown.gif";
 pic2= new Image(191,1);
 pic2.src=site_url+"site/images/layout/bg-dropdown-top.gif";
 pic3= new Image(191,1);
 pic3.src=site_url+"site/images/layout/bg-dropdown-bottom.gif";
 pic4= new Image(191,1);
 pic4.src=site_url+"site/images/layout/connect-icons.gif";
 pic5= new Image(191,1);
 pic5.src=site_url+"site/images/layout/home/connect-icons.gif";
 pic5= new Image(172,57);
 pic5.src=site_url+"site/images/layout/loaded.gif";
}

function showFacebook(URL){
	newX = (window.screen.width/2) - (250);
	newY = (180);
	window.open("http://www.facebook.com/sharer.php?u="+URL,"share","menubar=no,width=800,height=500,toolbar=no,screenX="+newX+",screenY="+newY);
}

function showTwitter(URL){
	newX = (window.screen.width/2) - (250);
	newY = (180);
	window.open("http://twitter.com/share?url="+URL+"&text=Check out this show at the Bijou!","share","menubar=no,width=800,height=500,toolbar=no,screenX="+newX+",screenY="+newY);
}

$('.share').mouseover(function(){
	$(this).css('width', '76px');
	$(this).children().css('display', 'block');
});
$('.share div').mouseout(function(){
	$(this).parent().css('width', '60px');
	$(this).css('display', 'none');
});



function resetHeroCaptions(){
	$('div.wrap-hero-home div.hero-content').css("left", "auto");
	$('div.wrap-hero-home div.hero-content').css("display", "none");
	$('div.wrap-hero-home div.hero1').css("display", "block");
}


var currentTab = 1;
var homeRotate = 0;

function resetGears(id){
	$('#tab'+id+' div.gear div.active-gear').fadeIn(500);
	$('#tab'+id+' div.gear div.inactive-gear').fadeOut(500);
	$('#tab'+currentTab+' div.gear div.inactive-gear').fadeIn(500);
	$('#tab'+currentTab+' div.gear div.active-gear').fadeOut(500);
}

function moveArrow(id){
	switch(id){
		case 1:
			newArrowPosition = -968;
		break;
		case 2:
			newArrowPosition = -905;
		break
		case 3:
			newArrowPosition = -845;
		break;
		case 4:
			newArrowPosition = -785;
		break;
		case 5:
			newArrowPosition = -723;
		break;
	}

	$('.wrap-content').animate({
	    backgroundPosition: newArrowPosition+"px 0"}, 550);

	if(currentTab != id){
		resetGears(id);
		$('#tab'+id).addClass('current');
		$('#tab'+currentTab).removeClass('current');
	}
	currentTab = id;
}

$('div.hero-info').mouseenter(function(){
	$('.hero-controls').css('display', 'block');
	$('.hero-controls').css('z-index', '15');
});
$('div.hero-info').mouseleave(function(){

		$('.hero-controls').css('display', 'none');
		$('.hero-controls').css('z-index', '10');

});

var currentHero = 1;
function scroll(target){
	if(currentHero != target){
		switch(target){
			case 'l':
				nextImage = findNext('l');
				$(".hero"+currentHero).fadeOut(300);
				$(".hero"+nextImage).fadeIn(300);
				$('td.nav'+currentHero).removeClass('active');
				$('td.nav'+nextImage).addClass('active');
				currentHero = nextImage;
			break;
			case 'r':
				nextImage = findNext('r');
				$(".hero"+currentHero).fadeOut(300);
				$(".hero"+nextImage).fadeIn(300);
				$('td.nav'+currentHero).removeClass('active');
				$('td.nav'+nextImage).addClass('active');
				currentHero = nextImage;
			break;
			default:
				$(".hero"+currentHero).fadeOut(300);
				$(".hero"+target).fadeIn(300);
				$('td.nav'+currentHero).removeClass('active');
				$('td.nav'+target).addClass('active');
				currentHero = target;
			break;
		}
	}
}

function clickScroll(direction){
	clearInterval(homeRotate)
	scroll(direction);
}

function findNext(direction){
	switch(direction){
 		case 'l':
 			if(currentHero > 1){
 		 		nextImage = currentHero - 1;
 		 		return nextImage;
 			}else{
 				nextImage = totalImages;
 		 		return nextImage;
 		 	}
 		break;
 		case 'r':
 			if(currentHero < totalImages){
 				nextImage = currentHero + 1;
 		 		return nextImage;
 			}else{
 				nextImage = 1;
 				return nextImage;
 			}
 		break;
 	}
}

function autoRotate(){
	scroll('r');
}

$(function(){
	homeRotate = setInterval("autoRotate()", 4500);
});

