// Liquidus Media Scripts
// I control Flash transparency - over-ride me inline with tr = 1 to turn off wmode=transparent
var tr = 0;
var hasflash = DetectFlashVer('8','0','0');

// We show and hide items
function show(d,i) {
	a = document.getElementById(d);
	if (!i) {
		a.className = "on";
	} else {
		a.className = "overon";
	}
}

function hide(d) {
	a = document.getElementById(d);
	a.className = "off";
}

// We adjust opacity
function opacity(object,opacity) {
		object.style.opacity = opacity/10;
		object.style.filter = 'alpha(opacity=' + opacity*10 + ')';
}

// I handle mouse-over states for images
function switcher(i) {
	var id = document.getElementById(i);
	var s = id.src;
	var type;
	var src;
	var nsrc;
	
	if (s.indexOf(".gif") >= 0) {
		type = ".gif";
	} else if (s.indexOf(".jpg") >= 0) {
		type = ".jpg";
	} else if (s.indexOf(".png") >= 0) {
		type = ".png";
	} else {
		alert("This is not an image.");
	}
	
	src = s.replace(type, "");
	
	if (src.indexOf("-on") == -1) {
		nsrc = src + "-on" + type;
	} else {
		nsrc = src.replace(/-on/, "");
		nsrc += type;
	}
	
	id.src = nsrc;
}

// I invoke Flash headline text
function fh2(head) {
	var hfl = head;
	if (hasflash == true) {
		var h1 = head.toUpperCase();
		var h2 = h1.replace(/&/, "%26");
		hfl = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="475" height="21">';
		hfl += '<param name="movie" value="Images/Headers.swf?tt=' + h2 + '" />';
		hfl += '<param name="quality" value="high" />';
		hfl += '<param name="wmode" value="transparent" />';
		hfl += '<embed src="Images/Headers.swf?tt=' + h2 + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="475" height="21" wmode="transparent"></embed>';
		hfl +='</object>';
	}
	
	document.write(hfl);
}

// I invoke Flash headline text
function fh(head) {
	var hfl = head;
	if (hasflash == true) {
		var h2 = head.replace(/&/, "%26");
		hfl = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="505" height="24">';
		hfl += '<param name="movie" value="Images/Headers2.swf?tt=' + h2 + '" />';
		hfl += '<param name="quality" value="high" />';
		hfl += '<param name="wmode" value="transparent" />';
		hfl += '<embed src="Images/Headers2.swf?tt=' + h2 + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="505" height="24" wmode="transparent"></embed>';
		hfl +='</object>';
	}
	
	document.write(hfl);
}

// I load Flash movies
function fl(url,w,h,t) {
	var fla = 'To view this content, you need the latest version of Adobe Flash. Download it for free from <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">www.adobe.com</a>.';
	if (hasflash == true) {
		fla = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + w + '" height="' + h + '">';
		fla += '<param name="movie" value="' + url + '" />';
		fla += '<param name="quality" value="high" />';
		fla += '<param name="allowFullScreen" value="true" />';
		fla += '<param name="flashVars" value="GoogleKey=ABQIAAAAaKFXE_D5YLh4pfx0nIwRDxS-IhmwoP2YlpA-MLInBj79-NJpVxTceD4mm2YU3atcXV4JziymsgRgYw">';
		if (tr == 0) {
			fla += '<param name="wmode" value="transparent" />';
		}
		fla += '<embed src="' + url + '" allowfullscreen="true" quality="high" flashvars="GoogleKey=ABQIAAAAaKFXE_D5YLh4pfx0nIwRDxS-IhmwoP2YlpA-MLInBj79-NJpVxTceD4mm2YU3atcXV4JziymsgRgYw"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ';
		if (tr == 0) {
			fla += 'wmode="transparent" ';
		}
		fla += 'width="' + w + '" height="' + h + '"></embed>';
		fla +='</object>';
	}
	else {
	fla += '<embed src="' + url + '" allowfullscreen="true" quality="high" flashvars="GoogleKey=ABQIAAAAaKFXE_D5YLh4pfx0nIwRDxS-IhmwoP2YlpA-MLInBj79-NJpVxTceD4mm2YU3atcXV4JziymsgRgYw"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ';
	if (tr == 0) {
		fla += 'wmode="transparent" ';
	}
	fla += 'width="' + w + '" height="' + h + '"></embed>';
	fla +='</object>';
	}
	
	if (t == null) {
		document.write(fla);
	} else {
		document.getElementById(t).innerHTML = fla;
	}
}

// I handle dropdown menu changes
function dropdown(d) {
	var dd = document.getElementById(d);
	var ddlink = dd.options[dd.selectedIndex].value;
	if (ddlink) {
		location.href = ddlink;
	}
}

// I submit the search form with basic validation
function searchsubmit() {
	var form = document.getElementById('LTVSearchF');
	var field = document.getElementById('LTVSearchT');
	var fieldvalue = field.value;
	if (fieldvalue.length == 0) {
		alert("Please enter a search term!")
	} else {
		form.submit();
	}
}

// I load the form and email overlays on the Demos page
function loadoverlay(id1, id2) {
	var browsew = document.documentElement.clientWidth;
	var browseh = (document.height !== undefined) ? document.height : document.body.offsetHeight;
	var totalheight = document.documentElement.scrollHeight;
	var overlay = document.getElementById(id1);
	var theform = document.getElementById(id2);
	overlay.style.width = browsew + "px";
	overlay.style.height = totalheight + "px";
	overlay.className = "overlay";
	theform.className = "contactForm";
	theform.style.left = (browsew - 500)/2 + 'px';
	theform.style.top = 100 + 'px';
}

function hideForm(id1) {
	var theform = document.getElementById(id1);
	theform.className = "off";
}

function closeoverlay(id1, id2) {
	var overlay = document.getElementById(id1);
	var theform = document.getElementById(id2);
	overlay.className = "off";
	theform.className = "off";
}

// I dynamically load the Demos Tabs with the right content from Demos/Tabs.aspx
var request;
var url;
var content;
var contentdiv;

function getcontent(tab, pgcnt) {
	request = null;
	var url = 'Demos/Tabs.aspx?Tab=' + tab;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (request != null) {
		request.open("GET",url,true);
		request.onreadystatechange = loadcontent;
		request.send(null);
		getfooter(pgcnt);
	} else {
		alert("Your browser cannot use this feature.");
	}
}

function loadcontent() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			content = request.responseText;
			contentdiv = document.getElementById("LTVDemos");
			contentdiv.innerHTML = content;
		} else {
			alert("No content!");
		}
	}
}

function getfooter(pgcnt) {
	request2 = null;
	var url = 'Demos/Tabs.aspx?Tab=' + pgcnt;
	if (window.XMLHttpRequest) {
		request2 = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (request2 != null) {
		request2.open("GET",url,true);
		request2.onreadystatechange = loadfooter;
		request2.send(null);
	} else {
		alert("Your browser cannot use this feature.");
	}
}

function loadfooter() {
	if (request2.readyState == 4) {
		if (request2.status == 200) {
			content = request2.responseText;
			contentdiv = document.getElementById("LTVDemosPageCount");
			contentdiv.innerHTML = content;
		} else {
			alert("No content!");
		}
	}
}

// I open a demo pop-up
function popwindow(url, demo) {
	switch (url) {
	case 1:
		url = 1;
		w = 800;
		h = 720;
		break;
	case 2:
		url = 2;
		w = 800;
		h = 700;
		break;
	case 3:
		url = 3;
		w = 720;
		h = 600;
		break;
	case 4:
		url = 3;
		w = 732;
		h = 620;
		break;
	case 5:
		url = 3;
		w = 720;
		h = 660;
		break;
	case 6:
		url = 3;
		w = 320;
		h = 240;
		break;
	case 7:
		url = 3;
		w = 300;
		h = 250;
		break;
	case 8:
		url = 3;
		w = 250;
		h = 250;
		break;
	case 9:
		url = 3;
		w = 720;
		h = 580;
		break;
	case 10:
		url = 3;
		w = 720;
		h = 560;
		break;
	case 11:
		url = 1;
		w = 800;
		h = 820;
		break;
	case 12:
		url = 3;
		w = 320;
		h = 240;
		break;
	case 13:
		url = 4;
		break;
	default:
		url = 1;
		w = 800;
		h = 720;
	}
	if (url < 3) {
		var win1 = window.open("Demo"+url+".aspx?Demo="+demo, "demo1", "width="+w+", height="+h+", resizable=no, scrollbars=no, menubar=no, location=yes");
	} 
	else if (url == 3){
		var win2 = window.open("Demo"+url+".aspx?Demo="+demo, "demo2", "width="+w+", height="+h+", resizable=no, scrollbars=no, menubar=no, location=no");
	}
	else if (url == 4) {
		var win3 = window.open("Demo"+url+".aspx?Demo="+demo, "demo3");
	}
}

// I tell the email form which demo link to include
function setemail(demo, page) {
	if (demo == null) {
		alert("No demo has been selected for email.");
		return false;
	}
	
	document.getElementById("EmailDemo").value = "http://www.liquidusmedia.com/demo" + page + ".aspx?Demo=" + demo;
}
