$(document).ready(function() {
	$('#contactdropbar a').click(function(){ //form drop code
		if($('#contactdrop').hasClass('active')){
			$('#contactdrop').removeClass('active').animate({marginTop: "-276"}, 1000);
		}else{
			$('#contactdrop').addClass('active').animate({marginTop: "0"}, 1000);
		}
	});
	
	$('#moreinfobutton').click(function(){ //form drop code
		if($('#contactdrop').hasClass('active')){
			$('#contactdrop').removeClass('active').animate({marginTop: "-276"}, 1000);
		}else{
			$('#contactdrop').addClass('active').animate({marginTop: "0"}, 1000);
		}
	});

	
	$('#contactForm .submit').click(function() {
		$('#contactForm .submit').attr("disabled", "true");
		
		$('#contactForm').ajaxSubmit({
			'dataType': 'json',
			'success':
				function(data) {
					$('#contactForm .submit').removeAttr('disabled');
					$('#contactForm input').removeClass('error');
					var valid = (data.valid)
					if (valid == 1){
						//valid, hide form and present message
						$('#contactForm .errormsg, #contactForm #contactdropform1, #contactForm #contactdropform2').fadeOut();
						$('#contactForm #contactformsuccess').fadeIn();
					}else{
						//invalid, highlight errors and show error message
						$('#contactForm .errormsg').fadeIn();
						var errors = (data.errorFields);
						for(var i=0; i<errors.length; i++) {
							var value = errors[i];
							$('#contactForm input[name='+value+']').addClass('error');
						}//end for loop
					}//end if
				}
		});
		
		return false;
	});
	$('#contactForm .errormsg').hide();
});
 

// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
};


function rmObj(myObj){
	if(myObj){
		if(myObj.hasChildNodes()){
			for(var i = 0;i < myObj.childNodes.length;i++){
				rmObj(myObj.childNodes[i]);
			}
		}
		myObj.parentNode.removeChild(myObj);
	}
}

function isEmail(s){ 
    if (s.trim() == "") return false;
    
    var i = 1;
    var sLength = s.length;

	while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function focusField(inputBox, txtDefault){
	if(inputBox.value == txtDefault){
		inputBox.value = "";	
	}
}

function blurField(inputBox, txtDefault){
	if(inputBox.value == ""){
		inputBox.value = txtDefault;	
	}		
}

function showPopUp(o){
	if(navigator.userAgent.indexOf("Macintosh") != -1 && navigator.userAgent.indexOf("Firefox") != -1){
		var objInitEmbeds = document.getElementsByTagName("EMBED");	
		for(var i = 0;i < objInitEmbeds.length;i++){
			if(objInitEmbeds[i].className != "popupEmbed"){
				objInitEmbeds[i].style.visibility = "hidden";
			}
		}
	}
	
	var div = document.createElement("DIV");
	div.style.width = "100%";
	div.style.height = "100%";
	div.style.position = "absolute";
	div.style.top = "0px";
	div.style.left = "0px";
	div.style.zIndex = "10000";
	div.id = "popup_framework";
	
	var bg = document.createElement("DIV");
	bg.style.width = "100%";
	bg.style.height = "100%";
	bg.style.position = "absolute";
	bg.style.top = "0px";
	bg.style.left = "0px";
	bg.style.zIndex = "10000";
	if(!(navigator.userAgent.indexOf("Macintosh") != -1 && navigator.userAgent.indexOf("Firefox") != -1)){
		bg.style.backgroundColor = "#000033";
		bg.style.opacity="0.84";
		bg.style.filter="alpha(opacity=84)";
	}
	else{
		bg.style.backgroundImage="url(/images/video-player-lb/lb_page_background.png)";	
	}

	div.appendChild(bg);
	
	var table = document.createElement("TABLE");
	table.style.width = "100%";
	table.style.height = "100%";
	table.border = 0;
	table.cellPadding = 0;
	table.cellSpacing = 0;
	table.style.position = "absolute";
	table.style.zIndex = "10000";
	
	if(window.innerHeight){
		table.style.display = "table";
	}
	else{
		table.style.display = "block";	
	}
	table.style.top = "0";
	table.style.left = "0";

	div.appendChild(table);
	
	var tr = document.createElement("TR");
	tr.style.width = "100%";
	tr.style.height = "100%";

	table.appendChild(tr);
	
	var td = document.createElement("TD");
	td.style.width = "100%";
	td.style.height = "100%";
	td.vAlign = "middle";
	td.style.verticalAlign = "middle";
	td.style.textAlign = "center";

	tr.appendChild(td);
	
	td.appendChild(o);
	
	document.getElementsByTagName("BODY")[0].appendChild(div);
	if(!window.innerHeight){
		if(document.getElementById("pop_video_player_bg")){
			document.getElementById("pop_video_player_bg").style.backgroundImage = "none";	
		}
		document.getElementById("popup_framework").innerHTML = document.getElementById("popup_framework").innerHTML;
	}

	var objEmbeds = document.getElementsByTagName("EMBED");
	for(var i=0; i < objEmbeds.length; i++){
		for(var j=0; j<objEmbeds[i].attributes.length; j++){
			if(objEmbeds[i].attributes[j].name == "wmode"){
				objEmbeds[i].attributes[j].value = "transparent";
			}
		}
	}

	document.getElementsByTagName("HTML")[0].style.overflow = "hidden";
	if(window.innerHeight){
		document.getElementsByTagName("BODY")[0].style.overflow = "hidden";
	}
	window.scrollTo(0,0);
}

function closePopup(){
	if(navigator.userAgent.indexOf("Macintosh") != -1 && navigator.userAgent.indexOf("Firefox") != -1){
		var objInitEmbeds = document.getElementsByTagName("EMBED");	
		for(var i = 0;i < objInitEmbeds.length;i++){
			if(objInitEmbeds[i].className != "popupEmbed"){
				objInitEmbeds[i].style.visibility = "visible";
			}
		}
	}

	var divs = document.getElementsByTagName("DIV");
	for(var i=0;i < divs.length;i++){
		if(divs[i].className == "delete_popup"){
			divs[i].style.display = "none";
		}
	}
	
	rmObj(document.getElementById("popup_framework"));
	
	document.getElementsByTagName("HTML")[0].style.overflow = "auto";
	if(window.innerHeight){
		document.getElementsByTagName("BODY")[0].style.overflow = "auto";
	}
	
	var objEmbeds = document.getElementsByTagName("EMBED");
	for(var i=0; i < objEmbeds.length; i++){
		for(var j=0; j<objEmbeds[i].attributes.length; j++){
			if(objEmbeds[i].attributes[j].name == "wmode"){
				objEmbeds[i].attributes[j].value = "window";
			}
		}
	}
}

function popupPage(url){
	global_php_getHTML("","",url,"popupPage");
}

function global_php_return(action, response){
	if(action == "popupPage"){
		if(response != 0 && response != false){
			showPopUp(response);
		}
	}
}

function track(url){
	pageTracker._trackPageview(url);
}

function clearSubmenu(subMenu){
	
	if(!window.innerHeight){
		var subMenus = subMenu.getElementsByTagName("UL");
		for(var i = 0;i < subMenus.length;i++){
			subMenus[i].style.display = "none";
		}
	}
	
	var parent_node = subMenu.parentNode;

	while(parent_node.tagName != "LI") {
		parent_node = parent_node.parentNode;		
	}
	var target_element = parent_node.getElementsByTagName("A")[0];
	//alert(target_element.className., "current");
	if(target_element.className.indexOf("current") != -1){
		target_element.className = "current title";
	}
	else{
		
		target_element.className = "title";
		
	}

	
}

function showSubmenu(subMenu){
	if(!window.innerHeight){
		var subMenus = subMenu.getElementsByTagName("UL");
		for(var i = 0;i < subMenus.length;i++){
			subMenus[i].style.display = "block";
		}
	}
	var parent_node = subMenu.parentNode;

	while(parent_node.tagName != "LI") {
		parent_node = parent_node.parentNode;		
	}
	
	var target_element = parent_node.getElementsByTagName("A")[0];
	
	target_element.className += " a_hover";
	
}
