var cinmode = '';

function cinemamode(mode)
{
  if (mode == 1)
  {
	// turn on
    resizecinema();
	cinmode=1;
	document.getElementById('playerdiv').style.zIndex = '100';
	changeOpac(0,'cinemamodebg');
	document.getElementById('cinemamodebg').style.display = '';
	opacity('cinemamodebg', 0, 75, 750);

  }
  else
  {
	// turn off
	opacity('cinemamodebg', 75, 0, 500);
	setTimeout("document.getElementById('playerdiv').style.zIndex = '0';",750);
	setTimeout("document.getElementById('cinemamodebg').style.display='none';",750);

	cinmode=0;
  }
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function resizecinema()
{
  document.getElementById('cinemamodebg').style.width  = document.body.clientWidth;
  document.getElementById('cinemamodebg').style.height = document.body.clientHeight;
}

function show_watch_overs(watchid)  { 
	
	$("#playerwrap").hide();
	$("#sourcelist").hide();
	$("#emailshare").hide();
	$("#reportbroken").hide();
	$("#reviewepisode").hide();
	$("#watchovershare").show();
	$(watchid).show();

	
}

function submitEpisodeLink (query) {

	ajaxUpdater('#addlinkresults','/includes/ajax/submitepisodelink.php?' + query);
			
}
		
		
$(document).ready(function(){
	//check browser
	if (vsource == "zs") {
		if (/Firefox/.test(navigator.userAgent)){ 
			$("#playerdiv").load('/includes/ajax/ad1s.php?ai=' + aiv); 
			$("#playerdiv").show();
		} else {
			$("#playerdiv").show();
		}
	} 
	if (vsource == "other") {
		$("#playerdiv").load('/includes/ajax/ad1s.php?ai=' + aiv); 
		$("#playerdiv").show();
	}
			

	// close buttons
	$(".watchovers div.close").click(function() {
		$(".watchovers").hide();
		$("#watchovershare").hide();	
		$("#playerwrap").show();
		
		
	});
	
	 // bind to the link form's submit event 
	$('#submitLink').submit(function() { 
	   var query1 = $('#submitLink :text').fieldSerialize();
	   var query2 = $('#submitLink :hidden').fieldSerialize();
		submitEpisodeLink(query1 + '&' + query2);
		
		//stop default behaviour
		return false; 
	}); 
});
