var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1570089-1']);
_gaq.push(['_trackPageview']);

var ipad_ext = "";
var is_ipad = false;
if (navigator.userAgent.match(/iPad/i) != null) {
	ipad_ext = "_ipad";
	is_ipad = true;
}

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

(function() {
	var po = document.createElement('script');
	po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

function category_selected(loop) {
	TabID = category_tab_id_js[loop];
	CategoryID = category_cat_id_js[loop];
	Name = category_convert_name_js[loop];

	document.getElementById('search_category').value = category_name_js[loop];
	document.getElementById('category_dropdown').style.display = 'none';
	document.getElementById('category_dropdown_click').style.display = 'none';
	
	if (CategoryID == "W5338") {
		window.location.href = "/page-sunrise_sunset.html";
	} else if (CategoryID == "W5177") {
		window.location.href = "/" + Name + "page-display-info-tabid-" + TabID + ".html";
	} else if (TabID == "T5618") {
		window.location.href = "/" + Name + "page-display-info-tabid-T5175-regid-1-prodid-W5619-catid-" + CategoryID + ".html";
	} else if (TabID == "T5175") {
		window.location.href = "/" + Name + "page-display-info-tabid-T5175-regid-" + CategoryID + ".html";
	} else if (TabID == "T5852") {
		window.location.href = "/" + Name + "page-display-info-tabid-T5852-srcid-" + CategoryID + ".html";
	} else {
		window.location.href = "/" + Name + "page-display-info-tabid-" + TabID + "-catid-" + CategoryID + ".html";
	}
}

function reset_length() {
	var wrapper = document.getElementById('wrapper');
	var wrapperipod = document.getElementById('wrapper_ipod');
	
	if (wrapper != null) wrapper.style.height = "1800px";
	if (wrapperipod != null) wrapperipod.style.height = "1800px";
}

function image_swap(id_object, image_name) {
	id_object.src='/images/'+image_name;
}

function image_swap_multi_category(id_object, image_name_down, image_name_up) {
	if (category_dropdown_visible == false) {
		id_object.src='/images/'+image_name_down;
	} else {
		id_object.src='/images/'+image_name_up;
	}
}

function image_swap_multi_category_dropdown(id_object, image_name_down, image_name_up) {
	if (category_dropdown_expand == false) {
		id_object.src='/images/'+image_name_down;
	} else {
		id_object.src='/images/'+image_name_up;
	}
}

var mouseover_category_dropdown = false;

var category_dropdown_interval = null;
var category_dropdown_click_interval = null;

var category_dropdown_height = 1;
var category_dropdown_left = 780;
var category_dropdown_width = 198;

var category_dropdown_click_height = 0;
var category_dropdown_click_left = 765;

var category_dropdown_visible = false;
var category_dropdown_expand = false;

var browser_offset = 0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

var key_num = null;

var CatId = null;

if (isIE == false) browser_offset = 10;

function ClickSearch(id_object) {
	if (id_object.value == "Keyword Search") id_object.value = "";
	if (id_object.value == "Equipment Search") id_object.value = "";
	id_object.style.color = "#000000";
}

function BlurSearch(id_object, equipment) {
	if (id_object.value == "") {
		id_object.value = equipment + " Search";
		id_object.style.color = "#666666";
	}
}

function ClickCategory() {
	var search_category = document.getElementById('search_category');
	if (search_category.value == "Category Search") search_category.value = "";
	search_category.style.color = "#000000";
}

function BlurCategory(id_object) {
	if (id_object.value == "") {
		id_object.value = "Category Search";
		id_object.style.color = "#666666";
	}
}

function MouseOverSearchCategory() {
	mouseover_category_dropdown = true;
}

function MouseOutSearchCategory() {
	mouseover_category_dropdown = false;
}

function ClickSearchCategory() {
	var category_dropdown = document.getElementById('category_dropdown');
	var category_dropdown_click = document.getElementById('category_dropdown_click');

	if (category_dropdown.style.display == 'block') {
		category_dropdown_visible = false;
		clearInterval(category_dropdown_interval);
		category_dropdown_interval = setInterval("animate_dropdown_up()",25);
	} else {
		category_dropdown_visible = true;
		clearInterval(category_dropdown_interval);
		category_dropdown_interval = setInterval("animate_dropdown_down()",25);
		category_dropdown.style.display = 'block';
		category_dropdown_click.style.display = 'block';
	}
	
	var search_category = document.getElementById('search_category');
	search_category.focus();
	ClickCategory();
}

function CloseSearchCategory() {
	var category_dropdown = document.getElementById('category_dropdown');
	var search_category_click = document.getElementById('search_category_click');

	if (mouseover_category_dropdown == false) {
		if (category_dropdown_visible == true) {
			category_dropdown_visible = false;
			image_swap_multi_category(search_category_click,"ArrowDownOut.png","ArrowUpOut.png");
			clearInterval(category_dropdown_interval);
			category_dropdown_interval = setInterval("animate_dropdown_up()",25);
		}
	}
}

function ClickSearchCategoryDropdown() {
	if (category_dropdown_expand == true) {
		category_dropdown_expand = false;
		clearInterval(category_dropdown_click_interval);
		category_dropdown_click_interval = setInterval("animate_dropdown_contract()",25);
	} else {
		category_dropdown_expand = true;
		clearInterval(category_dropdown_click_interval);
		category_dropdown_click_interval = setInterval("animate_dropdown_expand()",25);
	}
}

function MouseOverListSeachCategory(id_object) {
	if (category_dropdown_interval == null && category_dropdown_click_interval == null) {
		id_object.style.backgroundColor = '#aaaaaa';
	}
}

function MouseOutListSeachCategory(id_object) {
	id_object.style.backgroundColor = '#ffffff';
}

function SearchCategoryKeyup(id_object) {
	id_object.style.color = "#000000";

	if (category_dropdown_visible == false) {
		category_dropdown_visible = true;
		image_swap_multi_category(search_category_click,"ArrowDownOut.png","ArrowUpOut.png");
		clearInterval(category_dropdown_interval);
		category_dropdown_interval = setInterval("animate_dropdown_down()",25);
		category_dropdown.style.display = 'block';
		category_dropdown_click.style.display = 'block';
	} else {
		FillCategories(category_tab_id_js.length);
	}
	
	Set_Cookie( 'CategorySearch', id_object.value, 0, '/', '', '');
}

function FillCategories(counter) {
	var categroy_search = document.getElementById('search_category').value;
	var category_innerhtml = "";
	
	for(var loop = 0; loop < counter; loop++) {
		if (categroy_search == "Category Search" || category_name_js[loop].toLowerCase().indexOf(categroy_search.toLowerCase()) > -1 || category_alias_js[loop].toLowerCase().indexOf(":" + categroy_search.toLowerCase() + ":") > -1) { 
			category_innerhtml += "<div class='dropdown_item' onclick='category_selected(" + loop + ")' onmouseover='MouseOverListSeachCategory(this)' onmouseout='MouseOutListSeachCategory(this)'>" + category_name_js[loop] + "</div>";
		}
	}
	document.getElementById('list_search_category').innerHTML = category_innerhtml;
}

function SearchKeywordKeyup(id_object, key) {
	//clearInterval(reload_ads_interval);
	//reload_ads_interval = setInterval("reload_ads()", reload_time);

	innerHTML = "<br><b class='p10'>Loading Results...</b><br><br><br><br><br>";
	ids = "";
	
	if (getURLParam("tabid")) ids += "&tabid=" + getURLParam("tabid");
	if (getURLParam("regid")) ids += "&regid=" + getURLParam("regid");
	if (getURLParam("prodid")) ids += "&prodid=" + getURLParam("prodid");
	if (CatId) {
		ids += "&catid=" + CatId;
	} else {
		if (getURLParam("catid")) ids += "&catid=" + getURLParam("catid");
	}
	
	if (key.keyCode == 13) {
		query = "&keyword_search=" + id_object.value.replace("&", "#26");
		query += "&return=return" + ids;
		database_query('keyword_search', query);
	} else {
		query = "&keyword_search=" + id_object.value.replace("&", "#26");
		if (query != "&keyword_search=") {
			query += "&return=keypress" + ids;
			database_query('keyword_search', query);
		} else {
			innerHTML = "<b class='p10'>NO RESULTS FOUND</b>";
		}
	}
	
	Set_Cookie( 'KeywordSearch', id_object.value, 0, '/', '', '');
	document.getElementById('web_content' + ipad_ext).innerHTML = innerHTML;
}

function EquipmentKeywordKeyup(id_object, key) {
	innerHTML = "<br><b class='p10'>Loading Results...</b><br><br><br><br><br>";
	
	ids = "";
	if (getURLParam("tabid")) ids += "&tabid=" + getURLParam("tabid");
	if (getURLParam("regid")) ids += "&regid=" + getURLParam("regid");
	if (getURLParam("prodid")) ids += "&prodid=" + getURLParam("prodid");
	if (CatId) {
		ids += "&catid=" + CatId;
	} else {
		if (getURLParam("catid")) ids += "&catid=" + getURLParam("catid");
	}
	
	if (key.keyCode == 13) {
		query = "&equipment_search=" + id_object.value.replace("&", "#26");
		query += "&return=return" + ids;
		database_query('equipment_search', query);
	} else {
		query = "&equipment_search=" + id_object.value.replace("&", "#26");
		if (query != "&equipment_search=") {
			query += "&return=keypress" + ids;
			database_query('equipment_search', query);
		} else {
			innerHTML = "<b class='p10'>NO RESULTS FOUND</b>";
		}
	}
	
	Set_Cookie( 'EquipmentSearch', id_object.value, 0, '/', '', '');
	document.getElementById('web_content' + ipad_ext).innerHTML = innerHTML;
}

function SearchKeywordClick() {
	//clearInterval(reload_ads_interval);
	//reload_ads_interval = setInterval("reload_ads()", reload_time);

	innerHTML = "<br><b class='p10'>Loading Results...</b><br><br><br><br>";
	ids = "";
	
	if (getURLParam("tabid")) ids += "&tabid=" + getURLParam("tabid");
	if (getURLParam("regid")) ids += "&regid=" + getURLParam("regid");
	if (getURLParam("prodid")) ids += "&prodid=" + getURLParam("prodid");
	if (getURLParam("catid")) ids += "&catid=" + getURLParam("catid");
	
	query = "&keyword_search=" + document.getElementById('search_keyword').value.replace("&", "#26");
	query += "&return=return" + ids;

	database_query('keyword_search', query);
	Set_Cookie( 'KeywordSearch', document.getElementById('search_keyword').value, 0, '/', '', '');
	document.getElementById('web_content' + ipad_ext).innerHTML = innerHTML;
}

function EquipmentKeywordClick() {
	innerHTML = "<br><b class='p10'>Loading Results...</b><br><br><br><br>";
	ids = "";
	
	if (getURLParam("tabid")) ids += "&tabid=" + getURLParam("tabid");
	if (getURLParam("regid")) ids += "&regid=" + getURLParam("regid");
	if (getURLParam("prodid")) ids += "&prodid=" + getURLParam("prodid");
	if (getURLParam("catid")) ids += "&catid=" + getURLParam("catid");
	
	query = "&equipment_search=" + document.getElementById('equipment_keyword').value.replace("&", "#26");
	query += "&return=return" + ids;
	
	database_query('equipment_search', query);
	Set_Cookie( 'EquipmentSearch', document.getElementById('search_keyword').value, 0, '/', '', '');
	document.getElementById('web_content' + ipad_ext).innerHTML = innerHTML;
}

function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;

	if ( strHref.indexOf("-") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("-"));
		var aQueryString = strQueryString.split("-");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}

	return unescape(strReturn.replace(".html",""));
} 

function animate_dropdown_down() {
	var category_dropdown = document.getElementById('category_dropdown');
	var category_dropdown_click = document.getElementById('category_dropdown_click');

	if (category_dropdown) {
		var list_search_category = document.getElementById('list_search_category');
		list_search_category.innerHTML = '';

		category_dropdown_height += (450/5);
		category_dropdown.style.height = category_dropdown_height + "px";
		category_dropdown_click_height += (107/5);
		category_dropdown_click.style.height = category_dropdown_click_height + "px";

		if (category_dropdown_height >= 450) {
			clearInterval(category_dropdown_interval);
			category_dropdown_interval = null;
			setTimeout("FillCategories(category_tab_id_js.length)",1);
		}
	}
}

function animate_dropdown_up() {
	var category_dropdown = document.getElementById('category_dropdown');
	var category_dropdown_click = document.getElementById('category_dropdown_click');
	
	if (category_dropdown) {
		var list_search_category = document.getElementById('list_search_category');
		list_search_category.innerHTML = '';
		
		category_dropdown_height -= (450/5);
		category_dropdown.style.height = category_dropdown_height + "px";
		category_dropdown_click_height -= (107/5);
		category_dropdown_click.style.height = category_dropdown_click_height + "px";
	
		if (category_dropdown_height <= 2) {
			clearInterval(category_dropdown_interval);
			category_dropdown_interval = null;
			category_dropdown_height = 1;
			category_dropdown.style.height = 1 + "px";
			category_dropdown_click_height = 0;
			category_dropdown_click.style.height = 0 + "px";
			category_dropdown.style.display = 'none';
			category_dropdown_click.style.display = 'none';
		}
	}
}

function animate_dropdown_expand() {
	var category_dropdown = document.getElementById('category_dropdown');
	var category_dropdown_click = document.getElementById('category_dropdown_click');

	if (category_dropdown) {
		var list_search_category = document.getElementById('list_search_category');
		list_search_category.innerHTML = '';

		category_dropdown_left -= (200/5);
		category_dropdown_width += (200/5);
		category_dropdown.style.left = category_dropdown_left + "px";
		category_dropdown.style.width = category_dropdown_width + "px";
		category_dropdown_click_left -= (200/5);
		category_dropdown_click.style.left = category_dropdown_click_left + "px";
	
		if (category_dropdown_width >= 198+200) {
			clearInterval(category_dropdown_click_interval);
			category_dropdown_click_interval = null;
			setTimeout("FillCategories(category_tab_id_js.length)",1);
		}
	}
}

function animate_dropdown_contract() {
	var category_dropdown = document.getElementById('category_dropdown');
	var category_dropdown_click = document.getElementById('category_dropdown_click');

	if (category_dropdown) {
		var list_search_category = document.getElementById('list_search_category');
		list_search_category.innerHTML = '';

		category_dropdown_left += (200/5);
		category_dropdown_width -= (200/5);
		category_dropdown.style.left = category_dropdown_left + "px";
		category_dropdown.style.width = category_dropdown_width + "px";
		category_dropdown_click_left += (200/5);
		category_dropdown_click.style.left = category_dropdown_click_left + "px";
	
		if (category_dropdown_width <= 198) {
			clearInterval(category_dropdown_click_interval);
			category_dropdown_click_interval = null;
			category_dropdown_left = 780;
			category_dropdown_width = 198;
			category_dropdown_click_left = 765;
			category_dropdown.style.left = 780 + "px";
			category_dropdown.style.width = 198 + "px";
			category_dropdown_click.style.left = 765 + "px";
			setTimeout("FillCategories(category_tab_id_js.length)",1);
		}
	}
}

function animate_digital_network_dropdown_down() {
	var digital_network_dropdown = document.getElementById('digital_network_dropdown');

	if (digital_network_dropdown) {
		if (digital_network_dropdown_height >= digital_network_dropdown_max) {
			clearInterval(digital_network_dropdown_interval);
			digital_network_dropdown_interval = null;
		} else {
			digital_network_dropdown_height += (digital_network_dropdown_max/5);
			digital_network_dropdown.style.height = digital_network_dropdown_height + "px";
			digital_network_dropdown.style.display = 'block';
		}
	}
}

function animate_digital_network_dropdown_up() {
	var digital_network_dropdown = document.getElementById('digital_network_dropdown');

	if (digital_network_dropdown) {
		if (digital_network_dropdown.style.display == 'block') {
			digital_network_dropdown_height -= (digital_network_dropdown_max/5);
			digital_network_dropdown.style.height = digital_network_dropdown_height + "px";

			if (digital_network_dropdown_height <= 2) {
				clearInterval(digital_network_dropdown_interval);
				digital_network_dropdown_interval = null;
				digital_network_dropdown_height = 1;
				digital_network_dropdown.style.height = 1 + "px";
				digital_network_dropdown.style.display = 'none';
			}
		}
	}
}

LastLineClicked = null;

function StageChartTableColorChange_Click(TableLine) {
	if (LastLineClicked != null) {
		LastLineClicked.bgColor = LastLineColor;
	}
	
	LastLineClicked = TableLine;
	LastLineColor = CurrentLineColor;
	CurrentLineColor = '#ffff00';
	TableLine.bgColor = '#ffff00';
}

function StageChartTableColorChange_Over(TableLine) {
	CurrentLineColor = TableLine.bgColor;
	if (TableLine.bgColor != '#ffff00') {
		TableLine.bgColor = '#999999';
	}
}

function StageChartTableColorChange_Out(TableLine) {
	TableLine.bgColor = CurrentLineColor;
}

function AlignStageChartHeading() {
	document.getElementById('stage_chart_heading').scrollLeft = document.getElementById('stage_chart_body').scrollLeft;
}

function StageChartClick(Order, Stage) {
	document.getElementById('stage_chart_loading').innerHTML="<img src='/images/LoadingPleaseWait.gif' alt='LOADING PLEASE WAIT...' align='center'>";
	if (Order!=null) {
		Query = '&order=' +  Order + '&stage=' + Stage + '&is_ipad=' + is_ipad;
		database_query('stage_chart', Query);
	}
}

function ClickNewCalendarPage() {
	NewPage = '/page-events'
		+ '-month=' + document.getElementById('month_dropdown').value
		+ '-year=' + document.all('year_dropdown').value
		+ '.html';
		parent.location = NewPage;
}

var GoGreenClick = false;

function go_green_over(ObjectName) {
	document.getElementById('GoGreen').innerHTML = '';
	
	query = "&paidclient_record_locator=" + ObjectName;
	database_query('go_green', query);

	var Object = document.getElementById('grntop' + ObjectName);
	var ObjectTop = Object.offsetParent.offsetTop+Object.offsetTop;
	var ObjectHeight = document.getElementById('grnheight' + ObjectName).offsetHeight;

	document.getElementById('GoGreen').style.display='block';
	document.getElementById('GoGreen').style.top = ObjectTop+ObjectHeight+5+"px";
}

function qr_code_close() {
	document.getElementById('QRCode').style.display='none';
}

function qrcode_click(QRType, ObjectName, ObjectId) {
	document.getElementById('QRCode').innerHTML = '';
	
	query = "&qrtype=" + QRType + "&paidclient_record_locator=" + ObjectName;
	database_query('qr_code', query);

	var Object = document.getElementById('grntop' + ObjectId);
	var ObjectTop = Object.offsetParent.offsetTop + Object.offsetTop;
	var ObjectHeight = document.getElementById('grnheight' + ObjectId).offsetHeight;

	document.getElementById('QRCode').style.display='block';
	document.getElementById('QRCode').style.top = ObjectTop+ObjectHeight+5+"px";
}

LastLineClicked = null;

function SunriseSunsetTableColorChange_Click(TableLine, MonthDay) {
	if (LastLineClicked != null) {
		LastLineClicked.bgColor = LastLineColor;
		Month_Day = LastMonthDay.split("_");
		document.getElementById(Month_Day[0]).style.color = '#ffffff';
		document.getElementById(Month_Day[1]).style.color = '#ffffff';
	}
	
	LastLineClicked = TableLine;
	LastLineColor = CurrentLineColor;
	LastMonthDay = MonthDay;
	
	CurrentLineColor = '#ffff00';
	TableLine.bgColor = '#ffff00';
	Month_Day = MonthDay.split("_");
	document.getElementById(Month_Day[0]).style.color = '#ffff00';
	document.getElementById(Month_Day[1]).style.color = '#ffff00';
}

function SunriseSunsetTableColorChange_Over(TableLine) {
	CurrentLineColor = TableLine.bgColor;
	if (TableLine.bgColor != '#ffff00') {
		TableLine.bgColor = '#999999';
	}
}

function SunriseSunsetTableColorChange_Out(TableLine) {
	TableLine.bgColor = CurrentLineColor;
}

function go_green_out() {
	if (GoGreenClick == false) document.getElementById('GoGreen').style.display='none';
}

function go_green_click() {
	if (GoGreenClick == false) {
		GoGreenClick = true;
	} else {
		GoGreenClick = false;
	}
}

var digital_network_dropdown_interval = null;
var digital_network_dropdown_height = 1;
var digital_network_dropdown_max = 6 * 26;

function digital_network_over(id_object, image_name) {
	id_object.src = '/images/'+image_name;

	clearInterval(digital_network_dropdown_interval);
	digital_network_dropdown_interval = setInterval("animate_digital_network_dropdown_down()",100);
}

function digital_network_out(id_object, image_name) {
	id_object.src = '/images/'+image_name;

	clearInterval(digital_network_dropdown_interval);
	digital_network_dropdown_interval = setInterval("animate_digital_network_dropdown_up()",100);
}

function digital_network_menu_over() {
	clearInterval(digital_network_dropdown_interval);
	digital_network_dropdown_interval = setInterval("animate_digital_network_dropdown_down()",100);
}


function digital_network_menu_out() {
	clearInterval(digital_network_dropdown_interval);
	digital_network_dropdown_interval = setInterval("animate_digital_network_dropdown_up()",100);
}

var ImageInterval = new Array();
var EnlargePercent = new Array();
var EnlargeDirection = new Array();
var ObjectTop = new Array();
var ObjectLeft = new Array();
var ObjectWidth = new Array();
var ObjectHeight = new Array();
var zIndex = 1;

function pict_over(image, dir, max) {
	document.getElementById('div' + image).style.zIndex = zIndex++;
	
	if (ImageInterval[image]==null) {
		ImageInterval[image] = "";
		EnlargePercent[image] = 1;

		var Object = document.getElementById(image);
		var divObject = document.getElementById('div' + image);
		
		ObjectTop[image] = divObject.offsetTop;
		ObjectLeft[image] = divObject.offsetLeft;
		ObjectWidth[image] = Object.offsetWidth;
		ObjectHeight[image] = Object.offsetHeight;
	}

	if (ImageInterval[image]=="" || EnlargeDirection[image] == -.04) {
		clearInterval(ImageInterval[image]);
		EnlargeDirection[image] = .02;
		ImageInterval[image] = setInterval("ImageEnlarger('" + image + "', " + dir + ", " + max + ")",10);
	}
}

function pict_out(image, dir, max) {
	clearInterval(ImageInterval[image]);
	EnlargeDirection[image] = -.04;
	ImageInterval[image] = setInterval("ImageEnlarger('" + image + "', " + dir + ", " + max + ")",10);
}

function ImageEnlarger(image, dir, max) {
	EnlargePercent[image] = EnlargePercent[image] + EnlargeDirection[image];
	
	var Object = document.getElementById(image);
	var divObject = document.getElementById('div' + image);

	Object.width = ObjectWidth[image] * EnlargePercent[image];
	divObject.style.width = Object.width;
	Object.height = ObjectHeight[image] * EnlargePercent[image];
	
	switch (dir) {
		case 1:
			break;
		case 2:
			divObject.style.left = ObjectLeft[image] +
				(ObjectWidth[image] / 2) - (Object.width / 2);
			break;
		case 3:
			divObject.style.left = ObjectLeft[image] +
				(ObjectWidth[image]) - (Object.width);
			break;
		case 4:
			divObject.style.top = ObjectTop[image] +
				ObjectHeight[image] / 2 - Object.height / 2;
			break;
		case 5:
			divObject.style.left = ObjectLeft[image] +
				(ObjectWidth[image] / 2) - (Object.width / 2);
			divObject.style.top = ObjectTop[image] +
				ObjectHeight[image] / 2 - Object.height / 2;
			break;
		case 6:
			divObject.style.left = ObjectLeft[image] +
				(ObjectWidth[image]) - (Object.width);
			divObject.style.top = ObjectTop[image] +
				ObjectHeight[image] / 2 - Object.height / 2;
			break;
	}

	if (EnlargePercent[image] >= max) clearInterval(ImageInterval[image]);
	if (EnlargePercent[image] <= 1) {
		clearInterval(ImageInterval[image]);
		ImageInterval[image] = "";
		EnlargePercent[image] = 1;
	}
}

function ClickVideoShowcaseSpeaker() {
	if (speaker_state == 0) {
		speaker_state = 100;
		document.getElementById('showcase_speaker').src = '/images/speaker_on.png';
	} else {
		speaker_state = 0;
		document.getElementById('showcase_speaker').src = '/images/speaker_off.png';
	}

	jwplayer('video_small').setVolume(speaker_state);
	Set_Cookie( 'VideoShowcaseSpeaker', speaker_state, 14, '/', '', '' );
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function loadFile(obj, file_name) {
	query = "&file_name=" + file_name;
	database_query('video_showcase', query);

	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	if (isiPad) {
		document.getElementById('div_video_showcase_main').innerHTML="<video controls width=500 height=333><source src='" + obj['file'] + "' type='video/mp4' /></video>";
	} else {
		jwplayer('div_video_showcase_main').load(obj);
	}
}

var is_CHLinkClick = false;

function CHLinkClick() {
	if (document.getElementById("CHLinkHTML").style.display == "block") {
		document.getElementById("CHLinkHTML").style.display = "none";
	} else {
		document.getElementById("CHLinkHTML").style.top = document.getElementById("CHLinkButton").offsetTop + "px";
		document.getElementById("CHLinkHTML").style.height = document.getElementById("CHLinkButton").offsetHeight + "px";
		document.getElementById("CHLinkText").style.height = document.getElementById("CHLinkButton").offsetHeight - 30 + "px";
		document.getElementById("CHLinkHTML").style.display = "block";
		if (is_CHLinkClick == false) database_query('ch_link', '');
		is_CHLinkClick = true;
	}
}

var is_mouse_pressed = false;
var stage_chart_left = -1;
var stage_chart_right = -1;

function StageChartMouseDown() {
	is_mouse_pressed = true;
	stage_chart_left = -1;
	stage_chart_right = -1;
}

function StageChartMouseUp() {
	is_mouse_pressed = false;
}

function StageChartRepositionHeading() {
	if (is_mouse_pressed == true) {
		offsetX = stage_chart_left - window.event.clientX;
		offsetY = stage_chart_right - window.event.clientY;
		if (stage_chart_left != -1) {
			document.getElementById('stage_chart_heading').scrollLeft = document.getElementById('stage_chart_heading').scrollLeft + offsetX;
			document.getElementById('stage_chart_body').scrollLeft = document.getElementById('stage_chart_heading').scrollLeft;
		}
		stage_chart_left = window.event.clientX;
		stage_chart_right = window.event.clientY;
	}
}

function StageChartRepositionChart() {
	if (is_mouse_pressed == true) {
		offsetX = stage_chart_left - window.event.clientX;
		offsetY = stage_chart_right - window.event.clientY;
		if (stage_chart_left != -1) {
			document.getElementById('stage_chart_body').scrollLeft = document.getElementById('stage_chart_body').scrollLeft + offsetX;
			document.getElementById('stage_chart_heading').scrollLeft = document.getElementById('stage_chart_body').scrollLeft;
		}
		if (stage_chart_right != -1) {
			document.getElementById('stage_chart_body').scrollTop = document.getElementById('stage_chart_body').scrollTop + offsetY;
		}
		stage_chart_left = window.event.clientX;
		stage_chart_right = window.event.clientY;
	}
}

function video_border(id, color) {
	document.getElementById(id).style.borderColor = color;
}

function PlayNextVideo() {
	//return a random integer between 1 and playlist_max
	playlist_item = Math.floor(Math.random()*playlist_max) + 1;

	document.getElementById('video_small').src = media[playlist_item];
	document.getElementById('video_small').poster = poster[playlist_item];
	document.getElementById('video_small').load();
	var now_playing = title[playlist_item].split("|");
	var nowplaying = "";
	if (link[playlist_item] != "") nowplaying += "<a href = '" + link[playlist_item] + "'>";
	nowplaying += now_playing[1];
	if (link[playlist_item] != "") nowplaying += "</a>";
	document.getElementById('video_showcase_link').innerHTML = nowplaying;
}
