//=============================================================================
//-----------------------------------------------------------------------------
//	Player widget
//-----------------------------------------------------------------------------
//=============================================================================
// browser compatibility
function compatibility(id)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		return document.getElementById(id)
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		return document.all[id]
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		return document.layers[id]
	}
}

// skipitem() is called by next and prev buttons
function skipitem(i)
{
	skip = nowplaying * 1 + i * 1;

	if (mp_items[nowplaying][6] == 'images' && mp_items[skip][6] != 'images')
	{
		return null		
	}
	else if (mp_items[skip] && mp_items[skip][0] != 'full')
	{
		multiplayer(skip)
	}
	else
	{
		return null
	}
}

// category() is called by the category tab links
function category(cat)
{
	if (mp_categories)
	{
		// hide and show categories
		for (mp_category in mp_categories)
		{
			var catdiv = compatibility(mp_category + '_items')
			if (catdiv)
			{
				if (mp_category == cat)
				{
					catdiv.style.display = "block"
					swapImg('tab_' + mp_category, '/products/images/' + lang_code + '/tab_' + mp_category + '1.gif')
				}
				else
				{
					catdiv.style.display = "none"
					swapImg('tab_' + mp_category, '/products/images/' + lang_code + '/tab_' + mp_category + '0.gif')
				}
			}
		}
	}
	else
	{
		return null
	}
}

// multiplayer() is called by the item links
function multiplayer(i,autoplay)
{
	// keep track of which is playing
	nowplaying = i;
	
	if (mp_items[i])
	{
		if (mp_items[i][0] == 'full')
		{
			doFullsize(mp_items[i][0],mp_items[i][1],mp_items[i][2],mp_items[i][3],mp_items[i][4],true,mp_items[i][5],mp_items[i][6])
		}
		else if (autoplay == false)
		{
			doMultiplayer(mp_items[i][0],mp_items[i][1],mp_items[i][2],mp_items[i][3],mp_items[i][4],false,mp_items[i][5],mp_items[i][6])
		}
		else
		{
			doMultiplayer(mp_items[i][0],mp_items[i][1],mp_items[i][2],mp_items[i][3],mp_items[i][4],true,mp_items[i][5],mp_items[i][6])
		}
	}
	else
	{
		return null
	}

}

// make all page changes from the file info
function doFullsize(id,format,file,w,h,autoplay,clickaction)
{
	// hide show multiplayer
	var multiplayer = compatibility('multiplayer')
	var fullplayer = compatibility('fullplayer')
	multiplayer.style.display = "none"
	fullplayer.style.display = "block"
		
	// scale item to not break layout
	if (w && w != 803)
	{
		r = 803/w
		w = 803
		h = Math.round( h * r )
	}
	else if (!w)
	{
		w = 803
		h = 343
	}

	// display item
	if (file!='')
	{
		if (format=='')
		{
			// -=-=-=- flv -=-=-=-
			var so = new SWFObject('/products/product_video_758x321.swf?content_path='+file,'full_flv',w,h,'8','')
			so.addParam("wmode", "transparent")
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.write('fullplayer')
		}
		else 
		{
			// -=-=-=- other -=-=-=-
			var viewer = compatibility('fullplayer')
			if (format=='13')
			{
				// -=-=-=- swf -=-=-=-
				var so = new SWFObject(file,'full_swf',w,h,'8','')
				so.addParam("wmode", "transparent")
				so.addParam("menu", "false")
				so.addParam("quality", "high")
				so.write('fullplayer')
			}
			else if (format!='')
			{
				// -=-=-=- image -=-=-=-
				fullplayer.innerHTML = '<img id="viewer-img" src="' + file + '" width="' + w + '" height="' + h + '">'
			}
		}
		// add skip if there are items
		if (mp_items[1])
		{
//			fullplayer.innerHTML += '<div id="view_larger"><a href="#1" onclick="skipitem(1);;return false;">Skip Intro &raquo;</a></div>'
		}
	}
	else
	{
		// -=-=-=- no file -=-=-=-
		var viewer = compatibility('fullplayer')
		fullplayer.innerHTML = '&nbsp;'
		skipitem(1)
	}
}


// make all page changes from the file info
function doMultiplayer(id,format,file,w,h,autoplay,clickaction,cat)
{
	// hide show multiplayer
	var multiplayer = compatibility('multiplayer')
	var fullplayer = compatibility('fullplayer')
	multiplayer.style.display = "block"
	fullplayer.style.display = "none"

	// hide show categories
	category(cat)

	// hide and show item info and thumbnail css class
	for (mp_item in mp_items)
	{
		// active link
		var articleid = mp_items[mp_item][0]
		var itemlink = compatibility('item_link_' + articleid)
		if (itemlink)
		{
			if (mp_item == nowplaying)
			{
				itemlink.className = "active"
			}
			else
			{
				itemlink.className = ""
			}
		}
	}

	// display item
	if (file!='')
	{
		if (format=='flv')
		{
			// -=-=-=- flv -=-=-=-
			var so = new SWFObject('/products/product_video.swf?content_path='+file,'multi_flv','460','321','8','')
			so.addParam("wmode", "transparent")
			so.addParam("allowScriptAccess", "sameDomain")
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.addParam("scale", "noscale")
			so.write('player_area')
		}
		else if (format=='mp3')
		{
			// -=-=-=- mp3 -=-=-=-
			var so = new SWFObject('/products/product_audio.swf?content_path='+file,'multi_mp3','460','321','8','')
			so.addParam("wmode", "transparent")
			so.addParam("allowScriptAccess", "sameDomain")
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.addParam("scale", "noscale")
			so.write('player_area')
		}
		else if (format=='13')
		{
			// -=-=-=- swf -=-=-=-
			var so = new SWFObject(file,'multi_swf','460','288','8','#CCCCCC')
			so.addParam("wmode", "transparent")
			so.addParam("allowScriptAccess", "sameDomain")
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.addParam("scale", "scale")
			so.write('player_area')
		}
		else 
		{
			// -=-=-=- other -=-=-=-
			var viewer = compatibility('player_area')
			if (format!='')
			{
				// -=-=-=- image -=-=-=-
				// 	Scale item to not break layout
				if (w && w>460)
				{
					r = 460/w
					w = 460
					h = Math.round( h * r )
				}
				if (h && h>288)
				{
					r = 288/h
					h = 288
					w = Math.round( w * r )
				}
				// 	Center image
				hs = "0px"
				vs = "0px"
				if (w<460)
				{
					hs = Math.floor((460-w)/2) + "px"
				}
				if (h<288)
				{
					vs = Math.floor((288-h)/2) + "px"
				}

				if( clickaction )
				{
					viewer.innerHTML = '<a href="#" onclick="' + clickaction + ';return false;"><img id="viewer-img" src="' + file + '" width="' + w + '" height="' + h + '" style="margin:' + vs + ' 0 0 ' + hs + ';"></a>'
				}
				else
				{
					viewer.innerHTML = '<img id="viewer-img" src="' + file + '" width="' + w + '" height="' + h + '" style="margin:' + vs + ' 0 0 ' + hs + ';">'
				}
			}
			// add controls
			if( !suppress_slideshow )
			{
				//	Lightbox DHTML
//				viewer.innerHTML += '<div id="view_larger"><a href="#" onclick="' + clickaction + ';return false;"><img alt="previous" id="slideshow_plus" src="/products/images/en/slideshow_plus.gif" /></a></div>'
//				viewer.innerHTML += '<div id="prev_next"><a href="#" onmouseout="swapImg(\'slideshow_left\',\'/products/images/en/slideshow_left.gif\');" onmouseover="swapImg(\'slideshow_left\',\'/products/images/en/slideshow_left0.gif\');" onclick="skipitem(\'-1\');return false;"><img alt="previous" id="slideshow_left" src="/products/images/en/slideshow_left.gif" /></a><a href="#" onmouseout="swapImg(\'slideshow_right\',\'/products/images/en/slideshow_right.gif\');" onmouseover="swapImg(\'slideshow_right\',\'/products/images/en/slideshow_right0.gif\');" onclick="skipitem(\'1\');return false;"><img alt="next" id="slideshow_right" src="/products/images/en/slideshow_right.gif" /></a></div>'

				//	Link to the image only
				if( clickaction )
				{
					viewer.innerHTML += '<div id="view_larger"><a href="#" onclick="' + clickaction + ';return false;"><img alt="previous" id="slideshow_plus" src="/products/images/' + lang_code + '/slideshow_plus.gif" /></a></div>'
				}
//				viewer.innerHTML += '<div id="prev_next"><a href="#" onmouseout="swapImg(\'slideshow_left\',\'/products/images/en/slideshow_left.gif\');" onmouseover="swapImg(\'slideshow_left\',\'/products/images/en/slideshow_left0.gif\');" onclick="skipitem(\'-1\');return false;"><img alt="previous" id="slideshow_left" src="/products/images/en/slideshow_left.gif" /></a><a href="#" onmouseout="swapImg(\'slideshow_right\',\'/products/images/en/slideshow_right.gif\');" onmouseover="swapImg(\'slideshow_right\',\'/products/images/en/slideshow_right0.gif\');" onclick="skipitem(\'1\');return false;"><img alt="next" id="slideshow_right" src="/products/images/en/slideshow_right.gif" /></a></div>'
			}			
		}
	}
	else
	{
		// -=-=-=- no file -=-=-=-
		var viewer = compatibility('player_area')
		viewer.innerHTML = '&nbsp;'
	}
/*
	if( !clickaction )
	{
		document.getElementById( "view_larger" ).style.display	= "none";
	}
	else
	{
		document.getElementById( "view_larger" ).style.display	= "block";
	}
*/
}






/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;





//=============================================================================
//-----------------------------------------------------------------------------
//	FAQ widget
//-----------------------------------------------------------------------------
//=============================================================================
function ToggleFAQ( item )
{
	var item_count=0;

	//	Get the parent item (since the h3 was clicked on, we need to find the list item it belongs to)
	listitem	= item.parentNode;
	listitems	= listitem.childNodes;

	//	Search its child items for the div
	while( item.tagName != "DIV" )
	{
		item	= listitems[ item_count++ ];
	}

	current_display	= item.style.display;

	//	Get the tab container
	tab_container	= document.getElementById( 'info' );

	//	Make sure the container allows scrolling (this page's container, not the container of all tab pages)
	faq_container	= document.getElementById( 'info4' );
	faq_container.style.overflow	= "auto";

	//	Get the divs within the page container
	faq_items		= faq_container.getElementsByTagName( 'DIV' );

	//	Get the questions
	faq_questions	= faq_container.getElementsByTagName( 'H3' );

	//	Process each one
	for( faq_num = 0; faq_num < faq_items.length; faq_num++ )
	{
		//	If its not classed as a toggleable item, skip it
		if( faq_items[ faq_num ].className != "answer" )
		{
			continue;
		}

		//	Hide it
		faq_items[ faq_num ].style.display	= "none";

		//	Make quesiton inactive
		faq_items[ faq_num ].parentNode.firstChild.className	= "none";
	}

	//	Toggle the current item
	if( current_display == "" || current_display == "none" )
	{
		item.style.display	= "block";

		//	Make quesiton active
		item.parentNode.firstChild.className	= "active";
	}

	//	Scroll the container to the top of the active item
	faq_container.scrollTop	= listitem.offsetTop;

	//	Resize, custom for the FAQ page
	if( !infostatic_size )
	{
		//	Adjust container (group) object height
		document.getElementById( "info" ).style.height	= getOffsetHeight( "info4" ) + 'px';
	}
}

var current_toggle = "none";

function ToggleAll()
{
	if( current_toggle == "none" )
	{
		current_toggle = "block";
		question_toggle	= "active";
	}
	else
	{
		current_toggle = "none";
		question_toggle	= "none";
	}

	//	Make sure the container allows scrolling (this page's container, not the container of all tab pages)
	faq_container	= document.getElementById( 'info4' );
	faq_container.style.overflow	= "auto";

	//	Get the divs within the page container
	faq_items	= faq_container.getElementsByTagName( 'DIV' );

	//	Process each one
	for( faq_num = 0; faq_num < faq_items.length; faq_num++ )
	{
		//	If its not classed as a toggleable item, skip it
		if( faq_items[ faq_num ].className != "answer" )
		{
			continue;
		}

		//	Hide it
		faq_items[ faq_num ].style.display	= current_toggle;

		//	Make quesiton inactive
		faq_items[ faq_num ].parentNode.firstChild.className	= question_toggle;
	}

	//	Resize, custom for the FAQ page
	if( !infostatic_size )
	{
		//	Adjust container (group) object height
		document.getElementById( "info" ).style.height	= getOffsetHeight( "info4" ) + 'px';
	}
}

//=============================================================================
//-----------------------------------------------------------------------------
//	Form field reset
//-----------------------------------------------------------------------------
//=============================================================================
function ResetField( field, original_text )
{
	if( field.value == original_text )
	{
		field.value	= '';
	}
}

//=============================================================================
//-----------------------------------------------------------------------------
//	US/UK form switch
//-----------------------------------------------------------------------------
//=============================================================================
function SwitchDealerSearchForm( country )
{
	//	UK
	if( country == 'UK' )
	{
		//	Set form action for UK search
//		document.getElementById( 'dealer' ).setAttribute( 'action', '/sales/uk.php' );

		//	Toggle the fields
		document.getElementById( 'dealersearch-us' ).style.display	= "none";
		document.getElementById( 'dealersearch-uk' ).style.display	= "block";
	}

	//	US (default)
	else
	{
		//	Set form action for US search
//		document.getElementById( 'dealer' ).setAttribute( 'action', '/sales/index.php' );

		//	Toggle the fields
		document.getElementById( 'dealersearch-us' ).style.display	= "block";
		document.getElementById( 'dealersearch-uk' ).style.display	= "none";
	}

}
