$(document).ready(function() {
	init();			   
});

function init(){
$("#roomform").hide();
$(".folderform").hide();
$('#uploadcont').hide();


$("#rosternav").mouseover(function () {
$("#roster").slideDown("fast");
return false;
});

$(".mycontact").click(function () {
$.scrollTo( '#contacts', 500 );
return false;
});

$("#roster").mouseover(function () {
//$("#roster").stop(true);
return false;
});

$("#roster").mouseleave(function () {
//$("#roster").delay(1200).slideUp("fast");
return false;
});

$('.myabout').click(function () {
$(".aboutblock").slideToggle("fast");
$.scrollTo( 0, 500 );
return false;
});

$('.closeboxbut').click(function () {
$(".aboutblock").slideToggle("fast");
return false;
});

$('.close').click(function(){
	$('#videoplayer').slideUp();
});




};

//// get .MOV file for clientpage ////
$(function() {
		$('.openmov').live("click",function() {					
		var tempid = $(this).attr("id");
		var splitid = tempid.split("_");
		var id = splitid[1];
		var clicked = $(this);
		
		var string = 'spot_id=' + id;
			if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1))
			{
				/// if it's mobile safari
				$.ajax({
					type: "POST",
					url: "bucket/getmovipad.php",
					data: string,
					success: function(result){
						$("#vid2").html(result);
						
					}
				});
			}else{
				/// otherwise use the jw player		
				
				
					$.ajax({
						type: "POST",
						url: "bucket/getmov.php",
						data: string,
						success: function(result){
							//$("#rightcontainer").html(result);
							$("#content").html(result);
							
							/*$('#videoplayer').lightbox_me({
        						centered: true,
								overlayCSS: {background: 'white',opacity: .9},
								closeSelector: '.close'
							});*/
							$('#videoplayer').slideDown();
							$.scrollTo('100px');
					}
				});
			}
			return false;
		});
});

$(function() {
		$('.openmovhome').live("click",function() {					
		var tempid = $(this).attr("id");
		var splitid = tempid.split("_");
		var id = splitid[1];
		var clicked = $(this);
		
		var string = 'spot_id=' + id;
			if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1))
			{
				/// if it's mobile safari
				$.ajax({
					type: "POST",
					url: "bucket/getmovipadhome.php",
					data: string,
					success: function(result){
						$("#vid3").html(result);
						
						
					}
				});
			}else{
				/// otherwise use the jw player		
				
				
					$.ajax({
						type: "POST",
						url: "bucket/getmov.php",
						data: string,
						success: function(result){
							//$("#rightcontainer").html(result);
							$("#content").html(result);
							
							/*$('#videoplayer').lightbox_me({
        						centered: true,
								overlayCSS: {background: 'white',opacity: .9},
								closeSelector: '.close'
							});*/
							
							$('#videoplayer').slideDown();
							$.scrollTo('100px');
					}
				});
			}
			return false;
		});
});

//// get the clicked company
$(function() {
		$('.getco').live("click",function() {					
		var tempid = $(this).parent().attr("id");
		var splitid = tempid.split("_");
		var id = splitid[1];
		var clicked = $(this);
		
		var string = 'roster_id=' + id;
		
		$('#videoplayer').slideUp();
	
		$.ajax({
			type: "POST",
			url: "bucket/getcompany.php",
			data: string,
			success: function(result){
				$("#right-column").html(result);
				
				
							
				}
			});

		});
});


//// get the clicked company
$(function() {
		$('.getsection').live("click",function() {	
		$('.getsection').removeClass('active');
		$(this).addClass('active');				
		var id = $(this).attr("id");
		var sec = '';
		
		if (id =="cat_anim_design"){
			sec = 	203;
		}else if ( id =="cat_live_action"){
			sec = 204;
		}else if (id == 'cat_mixed_media'){
			sec = 205;
		}else if (id =="cat_digital"){
			sec = 206;
		}else{
			sec = 31; // must have selected "all"
		}
		
		var string = 'sec=' + id;
		
		$('#videoplayer').slideUp();
	
		$.ajax({
			type: "POST",
			url: "bucket/getbysection.php",
			data: string,
			success: function(result){
				$("#rosterlist").html(result);
				
					string = "roster_id="+sec;
					$.ajax({
						type: "POST",
						url: "bucket/getfrontreel.php",
						data: string,
						success: function(result){
							$("#right-column").hide();	
							$("#right-column").html(result);
							$("#roster").slideDown("slow");
							$("#right-column").delay(1000).fadeIn('slow');
				
							$('.closeboxbut').click(function () {
								$(".aboutblock").slideToggle("fast");
								return false;
							});
						}
					});
							
				}
			});

		});
		
		
		
		
		
		return false;
});


$.address.change(function(event) {  
    // do something depending on the event.value property, e.g.  
    // $('#content').load(event.value + '.xml');  
	
	var str = $.address.value();
	
	var myurl = str.replace("/", "");
	
	var hash = window.location.hash.split("?id");
	hash = hash[0]
	hash = hash.replace("#", "");
	console.log("hash="+hash);
	
	var spotid = getUrlVars()["id"];
	
	console.log(spotid);

	
	string =  "roster_id="+hash;

	if (myurl == ""){
		$.ajax({
			type: "POST",
			url: "bucket/gethesty.php",
			data: string,
			success: function(result){
				$("#right-column").hide();	
				$("#right-column").html(result);
				$("#roster").slideDown("slow");
				$("#right-column").delay(1000).fadeIn('slow');
				
				$('.closeboxbut').click(function () {
					$(".aboutblock").slideToggle("fast");
					return false;
				});
			}
		});
	}else{
		$('#videoplayer').slideUp();
		$.ajax({
			type: "POST",
			url: "bucket/getcompany.php",
			data: string,
			success: function(result){
				$("#right-column").hide();	
				$("#right-column").html(result);
				$.scrollTo( 0, 500 );
				//$("#roster").delay(1000).slideUp("slow");
				$("#right-column").delay(1000).fadeIn('slow');
				

			}
		});
	}
			
		

	
}); 


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
	
}



