﻿
/* Video Popup Functions 22/06/2010 */

/* Show and hide video popup */
function ShowVideo(sVideoReference) {

	var sVideo = '<a id="aVideoPopUpClose" title="Close" onclick="CloseVideoBox()"><span class="videoCloseButton"> </span></a>'
	sVideo = sVideo + '<object width="425" height="344">'
	sVideo = sVideo + '<param name="movie" value="http://www.youtube.com/v/' + sVideoReference + '&hl=en&fs=1" />'
	sVideo = sVideo + '<param name="allowFullScreen" value="true" />'
	sVideo = sVideo + '<param name="allowscriptaccess" value="always" />'
	sVideo = sVideo + '<embed id="embedVideo" src=http://www.youtube.com/v/' + sVideoReference + '&hl=en&fs=1 type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>'
	sVideo = sVideo + '</object>'
	

	var oDiv = f.GetObject('divVideoPopup')
	oDiv.innerHTML = sVideo

	e.ModalPopup.Show('divVideoPopup');

}

function CloseVideoBox() {
	e.ModalPopup.Close()
}


/* Hover Media function for single property/geographical area/*
if thumbnail is a video thumb then the mainImage.playImage needs also to be displayed and the video reference set*/
var MediaHover = new function() {

	this.VideoEvent = null;

	this.Hover = function(aLink, oMainImage, sMainImageURL, sImageTitle, sImageAlt, bVideo, sReference) {

		var oImage = f.SafeObject(oMainImage);
		oImage.src = sMainImageURL;
		if (sImageTitle != undefined) oImage.title = sImageTitle;
		if (sImageAlt != undefined) oImage.alt = sImageAlt;

		var aThumbnailLinks = f.GetObjectsByIDPrefix('aThumb', 'a');
		if (aThumbnailLinks.length > 1) {
			for (var i = 0; i < aThumbnailLinks.length; i++) {
				f.SetClassIf(aThumbnailLinks[i], 'selected', aThumbnailLinks[i] == aLink);
			}
		}

		var oMainImagePlayButton = f.GetObject('imgMainImagePlayButton');
		var oMainImageAnchor = f.GetObject('aMainImage');

		if (oMainImageAnchor != null) {
			oMainImageAnchor.setAttribute("onclick", "return false;");
		}
		
		if (bVideo) {
			//show the play button
			oMainImagePlayButton.style.display = 'block';
			//set the mainImage link to correct reference
			if (this.VideoEvent != null) {
				f.DetachEvent(this.VideoEvent);
			}
			this.VideoEvent = f.AttachEvent(oMainImageAnchor, 'click', function() { ShowVideo(sReference); });
		}
		else if (!bVideo) {

			//hide the play button
			oMainImagePlayButton.style.display = 'none';
			//set the mainImage link to nothing
			if (this.VideoEvent != null) {
				f.DetachEvent(this.VideoEvent);
			}
		}
	}
}


/* Hover Media funtion for a property search results */
var PropertyResultsMedia = new function() {

	this.VideoEvent = null;

	this.MediaHover = function(aLink, iPropertyID, sImageURL, bVideo, sReference) {
		f.GetObject('imgMainImage_' + iPropertyID).src = sImageURL;
		var aThumbnailLinks = f.GetObjectsByIDPrefix('aThumb_' + iPropertyID + '_', 'a');
		for (var i = 0; i < aThumbnailLinks.length; i++) {
			f.SetClassIf(aThumbnailLinks[i], 'selected', aThumbnailLinks[i] == aLink);
		}

		//find the correct mainImagePlayButton image
		var oMainImagePlayButton = f.GetObject('imgMainImagePlayButton_' + iPropertyID);
		var oMainImageAnchor = f.GetObject('aMainImage_' + iPropertyID);

		if (oMainImageAnchor != null) {
			oMainImageAnchor.setAttribute("onclick", "return false;");
		}

		if (bVideo) {
			oMainImagePlayButton.style.display = 'block';

			if (this.VideoEvent != null) {
				f.DetachEvent(this.VideoEvent);
			}

			this.VideoEvent = f.AttachEvent(oMainImageAnchor, 'click', function() { ShowVideo(sReference); });

		}

		else if (!bVideo) {
			if (oMainImagePlayButton != null) {
				oMainImagePlayButton.style.display = 'none';

				if (this.VideoEvent != null) {
					f.DetachEvent(this.VideoEvent);

					oMainImageAnchor.setAttribute('onclick', 'return false;');
				}
			}
		}
	}
}




/* Old Video function */
var Video = new function() {

	this.LoadVideo = function(id) {

		var sHotelName = f.GetHTML('hHotelName' + id);
		var sLocation = f.GetHTML('hLocation' + id);
		var sVideo = f.GetValue('hidFLV' + id);
		

		f.SetHTML('hVideoHotelName', sHotelName);
		f.SetHTML('lblVideoLocation', sLocation);

		var so = new SWFObject('http://lchtest.ivector.co.uk/Custom/LowCostHols/Videos/player.swf', 'mpl', '470', '298', '9');
		so.addParam('allowscriptaccess', 'always');
		so.addParam('allowfullscreen', 'true');
		so.addParam('flashvars', '&file=http://lchtest.ivector.co.uk/Custom/LowCostHols/Videos/' + sVideo + '&autostart=false&screencolor=#666666');
		so.write('divVideoHolder');

	}
}
