// JavaScript Document
var minopacity = 0.3;
var videoPlayer = "none";
var whichImage = 4;
var startImgCount = 4;
var checkClick = true;


jQuery(document).ready(function($) {
	fixhome();
	$("#wrapper-g").css({left: window.innerWidth}).animate({left: '0'}, 750);
	$(".main .rotate").jCarouselLite({
		btnNext: ".main .next",
		btnPrev: ".main .prev",
		speed: 500,
		easing: "easeinout",
		mouseWheel: false,
		circular:true,
		start:0,
		visible:3
	});	
	/*$('a[rel*=facebox]').facebox({
		loading_image : 'facebox/loading.gif',
		close_image   : 'facebox/closelabel.gif'
	});*/
	$('div#gallery ul li').css({opacity: 0.00}).animate({opacity: minopacity}, 750);	
	$('div#gallery ul li.show').css({opacity: minopacity}).addClass('show').animate({opacity: 1.0}, 750);
});

function closeVideo(pnl){
	document.getElementById("sandeepVideo").innerHTML = "";
	document.getElementById("sandeepVideoImg").style.display = 'block'
}

function playVideo(src, pnl){
	document.getElementById(pnl).innerHTML = '<embed src="http://www.monsoonco.com/sxsw/' + src +'" width="540" height="325" autoplay="true"> <div class="padding"><a href="javascript://" onclick="closeVideo('+ pnl + ');">Stop Video</a></div>';
	document.getElementById(pnl+"Img").style.display = 'none'
}

//document.getElementById("dummy").innerHTML = whichImage;

function trackli(or){	
	if(checkClick){		
		var UL = $('div#gallery  ul').children();
		var current  = $('div#gallery ul li.show');
		var p = UL.length;
		
		//var whichImage = Math.round(Math.random()*(p-1));
		//document.getElementById("dummy").innerHTML = whichImage;
		
		//Get next image, when it reaches the end, rotate it back to the first image	
		//var next =  ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#gallery ul li:first') : current.next()) : $('div#gallery ul li:first'));
		if(or == 'n'){
			//var next =  ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#gallery ul li:first') : current.next()) : $('div#gallery ul li:first'));	
			whichImage++;
			if(whichImage > 13)
			{
				startImgCount++;
				whichImage = 5;
			}		
	
		}else{
			//var next =  ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#gallery ul li:first') : current.prev()) : $('div#gallery ul li:first'));	
			whichImage--;
			if(whichImage < 1)
			{
				whichImage = 9;
			}
		}
		
		var next = $(UL[whichImage]);
		
		if(videoPlayer != "none")
		{
			var player_ids = videoPlayer.split(',');
			$("#" + player_ids[0]).hide();
			$("#sandeepVideoImg").show();
			videoPlayer = "none";
		}
		
	//	alert(next);
		
		//Set the fade in effect for the next image, the show class has higher z-index
		 checkClick = false;
		 next.css({opacity: minopacity})
		.addClass('show')
		.animate({opacity: 1.0}, 500, function(){checkClick = true});
	
		//Hide the current image
		current.animate({opacity: minopacity}, 500)
		.removeClass('show');
	}
}

function fixhome(){
	myWidth = window.innerWidth;
	
	if(myWidth <= 1280){
		document.getElementById("carouselHold").style.left = "-180px";
	}
	if(myWidth <= 1024)
	{
		document.getElementById("carouselHold").style.left = "-350px";
	}
}

function pageClicked(page){
	$("#content").hide("slow",function(){	
			$.ajax({
			url : "getPage="+page,
			success:function(html){
			$(this).html(html).show("slow");
			}
			})			
	})
}


