window.onload = function(){
//fixBPheaderTags(); //not in use
	updateFaveCinemaStars(); //referenced by ??, used by some At The Cinema pages
	loaded(); //referenced by cinemavenues.js, used by whereis code	in some At The Cinema pages
	getGeocode(); //referenced by cinemavenues.js, used by whereis code	in some At The Cinema pages
	javascript:MediaSmart.insertAllAds();
}


function updateFaveCinemaStars(){}
function loaded(){}
function getGeocode(){}


pathToJS = strTemplateResourcePath + "js";

function getDomainPath(){
	if ( document.location.host == 'bpmep.massive.com.au' || document.location.host == 'v8test.bigpondmovies.com' || document.location.host == 'v8staging.bigpondmovies.com' || document.location.host == 'v8proof.bigpondmovies.com' || document.location.host == 'www.bigpondmovies.com'	|| document.location.host == 'bigpondmovies.com' || document.location.host == 'v8test.bigpondmovies.com.au' || document.location.host == 'v8staging.bigpondmovies.com.au' || document.location.host == 'v8proof.bigpondmovies.com.au' || document.location.host == 'www.bigpondmovies.com.au'	|| document.location.host == 'bigpondmovies.com.au' ) {
		strDomainPath = "http://" + document.location.host + "/";
	} else {
		strDomainPath = "http://bpmep.massive.com.au/";
	}	
}

getDomainPath();
var strHwwPath = strDomainPath + "xmlfeeds/HWW/";
//var strShowtimesPath = strTemplateResourcePath + "showtimes/";
var strShowtimesPath = strDomainPath + "showtimes/";


var scrolling = false;

function myCallBackOnFinish(obj){
	scrolling = false;
}
function myCallBackOnStart(obj){
	scrolling  = true;
}
function getNextImage(){
	if(window.arrImg)
	 Effect.Fade('imgHolder', {duration: 1.0, beforeStart: myCallBackOnStart, afterFinish: function(){$('imgWrapper').innerHTML = "<div id='imgHolder'>"+arrImg[currentImage-1]+"</div>";writeImgTitle(currentImage-1);writeImgSupplier(currentImage-1);showPagination();//doUpdate(template_resource_path)
}});
	 currentImage++;
	 //imgHolder.innerHTML = arrImg[currentImage];
	return currentImage;
	//$('prevNext').innerHTML = '';
	
}
function getPrevImage(){
	if(window.arrImg)
	 Effect.Fade('imgHolder', {duration: 1.0, beforeStart: myCallBackOnStart, afterFinish: function(){$('imgWrapper').innerHTML = "<div id='imgHolder'>"+arrImg[currentImage-1]+"</div>";writeImgTitle(currentImage-1);writeImgSupplier(currentImage-1);showPagination();//doUpdate()
}
});
	//imgHolder.innerHTML = '<img src="images/temp_review_hero.jpg" width="300" height="210" alt="[IMG CAPTION HERE]" title="[IMG CAPTION HERE]';
 	 //imgHolder.innerHTML = arrImg[currentImage];
	 currentImage--;
        
	return currentImage;
	//$('prevNext').innerHTML = '';
	
}
function doUpdate(template_resource_path){
	var url = template_resource_path + 'article_gallery.aspx';
	var pars = 'imgid=' + currentImage;
	var target = 'imgHolder';	
	var myAjax = new Ajax.Updater(target, url, {evalScripts: true, method: 'get', parameters: pars, onComplete: function(){ fadeIn();}});
	
	
	//var captionAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, onComplete: function(){ fadeIn();}});
	
	
}
function fadeIn(){
	Effect.Appear('imgHolder', {duration: 1.0});	
}
function showPagination(){
	scrolling = false;
	if(currentImage == 1){
		$('prevNext').innerHTML = 'Previous | <a href="javascript:void(0);" onclick="if(scrolling==false){getNextImage();}">Next</a>';
		$('imgCount').innerHTML = "Image 1 of " + totalImages;
	}else if(currentImage == totalImages){
		$('prevNext').innerHTML = '<a href="javascript:void(0);" onclick="if(scrolling==false){getPrevImage();}">Previous</a> | Next';
		$('imgCount').innerHTML = "Image "+totalImages+" of " + totalImages;
	}else{
		$('prevNext').innerHTML = '<a href="javascript:void(0);" onclick="if(scrolling==false){getPrevImage();}">Previous</a> | <a href="javascript:void(0);" onclick="if(scrolling==false){getNextImage();}">Next</a>';
		$('imgCount').innerHTML = "Image "+currentImage+" of " + totalImages;
	}
	
}

document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

var xDist = 568;

function scrollRight(el, btn){
	newsArr=document.getElementsByClassName("newsBlock");
	var p = Position.positionedOffset($(el));
	var sm = $(el).getDimensions();
	var smw = (135+7) * newsArr.length;//sm.width;
	
	var scw = xDist;
	var offSet = -(smw - scw);
	var num = smw + p[0] - scw;

	if(p[0] > offSet  && scrolling == false){
		if(num > xDist){
			new Effect.MoveBy( $(el), 0, -xDist, { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );
		}else{
			//alert('zing!');
			new Effect.MoveBy( $(el), 0, -(num), { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );
			$(btn).className = 'rightInactiveHme';
		}
	}
	if(smw > xDist){
		$(btn).previous(1).className = 'btnLeftHme';
	}
}

function scrollToLeft(el, btn){
	newsArr=document.getElementsByClassName("newsBlock");
	var p = Position.positionedOffset($(el));
	var sm = $(el).getDimensions();
	var smw = (135+7) * newsArr.length;// sm.width;
	var scw = xDist;
	var offSet = -(smw - scw);
	var num = smw + p[0] - scw;
	if(p[0] < 0 && scrolling == false){
		if(p[0] <= -xDist){
			new Effect.MoveBy( $(el), 0, xDist, { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart });
		}else{
			new Effect.MoveBy( $(el), 0, Math.abs(p[0]), { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );
			
		}
		$(btn).next(1).className = 'btnRightHme';

	}
	
	if(p[0] >= -xDist ){
		$(btn).className = 'leftInactiveHme';	
	}
	
}

//carousels (different different version, sept 07, makes cDist a called-in variable instead of being set here)
//var cDist = 636;
//function scrollCarouselRight(el, btn){
function scrollCarouselRight(el, btn, cDist)
{
	// Supply a default cDist if not otherwise specified
	if (cDist == null) cDist = 636;
	var p = Position.positionedOffset($(el));
	var sm = $(el).getDimensions();
	var smw = sm.width;	
	var scw = cDist;
	var offSet = -(smw - scw);
	var num = smw + p[0] - scw;
	if(p[0] > offSet  && scrolling == false){
		if(num > cDist){
			new Effect.MoveBy( $(el), 0, -cDist, { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );
		}else{
			new Effect.MoveBy( $(el), 0, -(num), { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );
			$(btn).className = 'rightInactive';
		}
	}
	if(smw > cDist){
		$(btn).previous(0).className = 'btnLeft';
	}
}

//function scrollCarouselLeft(el, btn){
function scrollCarouselLeft(el, btn, cDist){
	var p = Position.positionedOffset($(el));
	var sm = $(el).getDimensions();
	var smw = sm.width;
	var scw = cDist;
	var offSet = -(smw - scw);
	var num = smw + p[0] - scw;
	if(p[0] < 0 && scrolling == false){
		if(p[0] <= -cDist){
			new Effect.MoveBy( $(el), 0, cDist, { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart });
		}else{
			new Effect.MoveBy( $(el), 0, Math.abs(p[0]), { afterFinish: myCallBackOnFinish, beforeStart: myCallBackOnStart } );			
		}
		$(btn).next(0).className = 'btnRight';
	}
	if(p[0] >= -cDist ){
		$(btn).className = 'leftInactive';	
	}
}


/*overlay code */
var hasFlash = false;
var overlayState = false;
var currentOverlay = null;
var currentBoxOverlaid = null;
function showBox(overlayID,boxID){
	try{
		parent.movie_player_frame.JSHide();
	}catch(ex){

	}
	if(hasFlash==true){
		$('content-1').update('');
	}
    Element.showOverlay(overlayID);
    $(boxID).style.display  = '';
	var el = document.getElementById(overlayID);
	bodyHeight = document.body.offsetHeight;
	containerHeight = document.getElementById('container').offsetHeight;
    if(bodyHeight > containerHeight){
    	el.style.height = bodyHeight + "px";
	}else{
    	el.style.height = containerHeight + "px";
	}
	//hide selects for IE	
	var selects = $('moviesContent').getElementsBySelector('select');
	selects.each(function(select){
		select.hide();
	});
	
	
//	$(boxID).show();
	$(boxID).style.display  = 'block';
	
    center(boxID);
    overlayState = true;
	currentOverlay = overlayID;
	currentBoxOverlaid = boxID;
    return false;
}

function hideBox(){
    $(currentOverlay).hide();
    $(currentBoxOverlaid).hide();
	
    overlayState = false;
	currentOverlay = null;
	currentBoxOverlaid = null;
    var selects = $('moviesContent').getElementsBySelector('select');
	selects.each(function(select){
		select.show();
	});
	$('placeHolder').update('');
	if($('friendForm'))	$('friendForm').show();
    return false;
}


window.onresize = function(){
	if(overlayState == true){
		var el = document.getElementById(currentOverlay);
		bodyHeight = document.body.offsetHeight;
		containerHeight = document.getElementById('container').offsetHeight;
	    if(bodyHeight > containerHeight){
	    	el.style.height = bodyHeight + "px";
    	}else{
	    	el.style.height = containerHeight + "px";
    	}
	    center(currentBoxOverlaid);
	}
}

window.onscroll = function(){
	if(overlayState == true){
		var el = document.getElementById(currentOverlay);
		bodyHeight = document.body.offsetHeight;
		containerHeight = document.getElementById('container').offsetHeight;
	    if(bodyHeight > containerHeight){
	    	el.style.height = bodyHeight + "px";
    	}else{
	    	el.style.height = containerHeight + "px";
    	}
		center(currentBoxOverlaid);
	}
}


function center(element){
	tempElement=element;
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;



    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
		//alert(1)
    }
	else if ( document.documentElement &&
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
			//alert(2)
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
		//alert(3)
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 103;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }


    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

	if(tempElement=='box' && document.all){
		setX=setX-10;
	}else if(tempElement=='box'){
		setX=setX-10;
	}
 
	if(homePage!=true){
		if(my_width > 1258){
			setX=setX-134;
		}else if (my_width > 990){
			setX=setX-((my_width-990)/2);
		}
	}	
	
	element.style.left = setX + "px";  
	$(element).setStyle({top: setY+'px'});
}


function sendToFriend(template_resource_path){
	var params = Form.serialize($('formTellAFriend'));
	var str = location.protocol + "//" + location.hostname + "/";
	if(str != template_resource_path){ 
		str = str + 'send_to_friend.aspx';
	}else{
		str = template_resource_path + 'send_to_friend.aspx';
	}
	new Ajax.Updater('placeHolder', str + "?resource=" + template_resource_path, {asynchronous:true, parameters:params, onComplete: function(){hideForm();}});
}
function hideForm(){
	Effect.BlindUp('friendForm', {scaleMode: 'contents', scaleFrom: 90, scaleTo: 20, duration: 1.0, afterFinish: function(){$('mailDone').show();}});
}


function contactBigpondMovies(template_resource_path){
	var params = Form.serialize($('formContactBigpondMovies'));
	var str = location.protocol + "//" + location.hostname + "/";
	if(str != template_resource_path){ 
		str = str + 'contact_bigpond_movies.aspx';
	}else{
		str = template_resource_path + 'contact_bigpond_movies.aspx';
	}
//new Ajax.Updater('placeHolder', str + "?resource=" + template_resource_path, {asynchronous:true, parameters:params, onComplete: function(){hideForm();}});
	new Ajax.Updater('placeHolder', str + "?resource=" + template_resource_path, {asynchronous:true, parameters:params, onComplete: function(){$('mailDone').show();}});
}

function manageSubscriptions(template_resource_path){
	var params = Form.serialize($('formManageSubscriptions'));
	var str = location.protocol + "//" + location.hostname + "/";
	if(str != template_resource_path){ 
		str = str + 'stay_in_touch.aspx';
	}else{
		str = template_resource_path + 'stay_in_touch.aspx';
	}
	new Ajax.Updater('placeHolder', str + "?resource=" + template_resource_path, {asynchronous:true, parameters:params, onComplete: function(){$('mailDone').show();}});
}

// old function used for opening popup windows, for image galleries
function openGallery(url, w, h){
	window.open(url, 'Gallery','width=' + w + ',height=' + h + ',scrollbars=0,resizable=no,toolbar=no');
	//window.open('./gallery_popup.php', 'Gallery','width=800,height=570,scrollbars=0,resizable=no,toolbar=no');
}

// generic function for opening popup windows
function openNewWindow(theURL,winName,features, myWidth, myHeight, isCenter) { 
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
	newWindow=window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	newWindow.focus()
}

// clear text fields when selected
function MM_setTextOfTextfield(objId,x,newText) {
  with (document){ if (getElementById){
    var obj = getElementById(objId);} if (obj) obj.value = newText;
  }
}

//	function for changing a css class
//			use: changeClass('name_of_target_id','name_of_new_class_within_target_id');
function changeClass(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

// toggling hidden elements between display:none and display:block
// 			use: onclick="toggleItem('id_of_hidden_element');return false"
function toggleItem(id){
	itemVisible = (document.getElementById(id).style.display == "block") ? false : true;
	document.getElementById(id).style.display = (itemVisible) ? "block" : "none";
}


// size an iframe to fit it's content
//			will not work if content is cross-domain
//			usage: <iframe id="ifrWhatever" id="ifrWhatever" src="whatever.html" width="100%" height="0" onload="ifrResizeHeight(this)">
//			   or: <iframe id="ifrWhatever" id="ifrWhatever" src="whatever.html" width="100%" height="0" onload="ifrResizeHeight('ifrWhatever')">
function ifrResizeHeight(iframe) { 
	iframe.height = window.frames[iframe.id].document.body.scrollHeight; 
}


function ifrFit(iframe, ifrHeight) {
	if(!ifrHeight) ifrHeight = 0;
	if ( ifrHeight == 0 || ifrHeight != window.frames[iframe.name].document.body.scrollHeight){
		ifrHeight = window.frames[iframe.name].document.body.scrollHeight;
		ifr_height_check = setTimeout(function() { ifrFit(iframe,ifrHeight);},500);
	}else{
		iframe.height = ifrHeight;
	}
}


//	function for getting querystrings
function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");											
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
		return args;
}

// function for getting current domain/page etc
// 		used to check whether environment is Dev, OMISP, or Production
// ALMOST CERTAIN THIS IS NOT USED
function getURL(uri) {
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}

var uri = new Object();
getURL(uri);


//	biscuits
//		usage: writeCookie("bpme_showtimes", "2020", 24);
function writeCookie(name, value, hours) {
  var expire = "";
  if(hours != null) {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
//		usage: readCookie("bpme_showtimes") ;
//		usage: alert( readCookie("bpme_showtimes") );
function readCookie(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}



//fix for bigpond header html (new c4 app) which we cannot modify and which has <a> tags opening within the iframe...
//this function adds a target of top to all links inside the iframe
//not yet in production, and no timetable for it. 
//refer tracker item #24664 for updates. 
/*
function fixBPheaderTags(){
	var ifr = document.getElementById("bpHeaderIframe"); 
	var oDoc = ifr.contentWindow || ifr.contentDocument;
	if (!oDoc.document){
		return null;
	}
	if( ifr ){
		var list = oDoc.document.getElementsByTagName("a");
		if( list ){
			for(var i=0, limit=list.length; i < limit; i++){
				list[i].target = '_top';
			}
		}
	}	
}
*/