//
//	jQuery
//
$(document).ready(function(){
			
	//
	//	Trailer overs
	//
	$("#panel_one_trailer, #panel_two_trailer").mouseover(function() {
		$(this).attr({ src: '/images/panels/trailer_ova.jpg' });
		
	}).mouseout(function() {
		$(this).attr({ src: '/images/panels/trailer.jpg' });
		
	}); 
	 
	//
	//	Now showing
	//
	var flashvars = { 
		datatarget: "/func/films.xml.php?show=now_showing&rand="+rand(), 
		direction: "right" 
	};
	var params = { 
		wmode: "opaque" 
	};
	var attributes = {};
	swfobject.embedSWF("/func/scrolling_photos.swf", "now_showing_flash", "728", "200", "9.0.0", false, flashvars, params, attributes);
	
	//
	//	Coming soon
	//
	var flashvars = { 
		datatarget: "/func/films.xml.php?show=coming_soon&rand="+rand(), 
		direction: "left" 
	};
	var params = { 
		wmode: "opaque" 
	};
	var attributes = {};
	swfobject.embedSWF("/func/scrolling_photos.swf", "coming_soon_flash", "728", "200", "9.0.0", false, flashvars, params, attributes);
	
});

var lastSetKey		= 0;
var setCount		= 0;
var homeFeatures	= new Array();
var hfTimer			= 15000;

function setPanel(div,arrFilm) {
			
	/*
	array map:
	
	0 = film title
	1 = film id
	2 = flv exists (true|false)
	
	*/
		
	// Set title
	$("#"+div+" .panel_title").html('<a href="/films/film_id='+homeFeatures[lastSetKey][1]+'">'+homeFeatures[lastSetKey][0]+'</a>');
	
	// Set trailer
	if(homeFeatures[lastSetKey][2]=='true') {
		var trailer = '<img src="'+'/images/panels/trailer.jpg" alt="Play Trailer" width="80" height="31" border="0"  class="showtrailer" id="'+div+'_trailer" flvid="'+homeFeatures[lastSetKey][1]+'" />';
	} else {
		var trailer = '<img src="'+'/images/panels/no_trailer.jpg"  width="80" height="31" border="0" />';
	}
	$("#"+div+" .panel_trailer").html(trailer);
	
	// Set href
	$("#"+div+" a").attr({ href: '/films/film_id='+homeFeatures[lastSetKey][1] });
	
	// Img src
	$("#"+div+" .feature_image").attr({ src: 'http://media.bcg.net.nz/bcg/uploads/panels/'+homeFeatures[lastSetKey][1]+'.jpg' });
		
}

function triggerHomeFeatures() {
	
	var len = (homeFeatures.length-1);
	
	if(len<2) {
		// Insert apology
		$("#panel_one, #panel_two").html("<div style=\"margin-top: 30px; margin-left:30px;\">Sorry, no featured films to display.</div>");
		return false;
	} else {
		
		lastSetKey = 1;
		setPanel('panel_one');
		
		lastSetKey = 2;
		setPanel('panel_two');
		
		$("#panel_one table, #panel_two table").fadeIn();
		
		// Only cycle if more than 2
		if(len>2) setInterval("cycleHomeFeatures()",hfTimer);

	}
}

function cycleHomeFeatures() {

	$("#panel_one table").fadeOut('slow',function() {
	
		var len = (homeFeatures.length-1);
		//
		// Panel 1
		//
		if((lastSetKey+1)>len) {
			lastSetKey = 0;
		}
		lastSetKey += 1;
		
		setPanel('panel_one');
		
		//
		//	Bring back panels
		//
		$("#panel_one table").fadeIn();
		

	});
	
	$("#panel_two table").fadeOut('slow',function() {
	
		var len = (homeFeatures.length-1);

		//
		// Panel 2
		//
		if(lastSetKey==len) {
			lastSetKey = 0;
		}
		lastSetKey +=1;
		
		setPanel('panel_two');
		
		//
		//	Bring back panels
		//
		$("#panel_two table").fadeIn();
		
	});
	
}


function jsAlert(js)  {  
     eval(js);  
}
