//toggle login header 

function hideDivStandard(divid) {
	if (document.getElementById(divid) != null)
	{
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(divid).style.visibility = 'hidden';
		}
		else {
			if (document.layers) { // Netscape 4
				document.hideShow.visibility = 'hidden';
			}
			else { // IE 4
				document.all.hideShow.style.visibility = 'hidden';
			}
		}

	}
}
function showDivStandard(divid) {
	if (document.getElementById(divid) != null)
	{
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(divid).style.visibility = 'visible';
		}
		else {
			if (document.layers) { // Netscape 4
				document.hideShow.visibility = 'visible';
			}
			else { // IE 4
				document.all.hideShow.style.visibility = 'visible';
			}
		}
	}
} 

function showLoginHdr() {
	if(document.getElementById("hdrResponse")){
		document.getElementById("hdrResponse").style.display="none";
	}
	Effect.toggle('login_header','appear',{duration:0.5});
    setTimeout('document.getElementById(\'username\').focus()', 600);
}

function showDiv(idName)
{
	Effect.toggle(idName,'appear',{duration:0.5});
  //  setTimeout('document.getElementById(\'username\').focus()', 600);
		
}

function hideDiv(idName)
{
	if(document.getElementById(idName)){
		document.getElementById(idName).style.display="none";
	}

}

//case studies rollover
function hoverOver(object) {
	theClass = object.className;
	newClass = theClass + " hover";
	object.className = newClass;
}

function hoverOut(object) {
	RemoveClassName(object, "hover");
}

function RemoveClassName(objElement, strClass) {
   // if there is a class
   if ( objElement.className )
      {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');
      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();
      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {
            // remove array item
            arrList.splice(i, 1);
            // decrement loop counter as we have adjusted the array's contents
            i--;
            }
         }
      // assign modified class name attribute
      objElement.className = arrList.join(' ');
      }
   // if there was no class
   // there is nothing to remove
}
//nav hover state

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function toggleBox(divId, toggleBoxId)
{
	if(document.getElementById(divId).style.display != 'none')
	{
		new Effect.BlindUp(divId, {duration: 0.6, queue: 'start' });
		document.getElementById(toggleBoxId).style.backgroundImage="url('../_img/nav_previouscontests.jpg')";
	} else {
		new Effect.BlindDown(divId, {duration: 0.6, queue: 'start' });
		document.getElementById(toggleBoxId).style.backgroundImage="url('../_img/nav_hide_previous.jpg')";
	}
	
}
//expanding content in details section
function expandContest(box) {
	
	opener = document.getElementById(box);
		if(document.getElementById("news").style.display != 'none')
		{
			closer = 'news';
			
		}
		if (document.getElementById("about").style.display != 'none')
		{
			closer = 'about';
			
		}
		if (document.getElementById("prizes").style.display != 'none')
		{
			closer = 'prizes';
			
		}
		if (document.getElementById("rules").style.display != 'none')
		{
			closer = 'rules';
			
		}
		startTimeline(closer, box);
}

function expandDropDowns(openBox, closeBoxes)
{
	opener = document.getElementById(openBox);
	
	for(i=0; i<closeBoxes.length; i++) { 
	   
	   	if(document.getElementById(closeBoxes[i]).style.display != 'none')
		{
			closer = closeBoxes[i];
			
		}
	}
	startTimeline(closer, opener);
}

//expanding content in details section
function expandHome(box) {
	if (document.getElementById(box).style.display=='')
	{
		//Effect.toggle(opener,'blind',{duration:0.5});
	}else {
		if(document.getElementById("about").style.display != 'none')
		{
			closer = 'about';
		}
		if (document.getElementById("news").style.display != 'none')
		{
			closer = 'news';
		}
		if (document.getElementById("login").style.display != 'none')
		{
			closer = 'login';
		}
		startTimeline(closer, box);
	}
}

function startTimeline(closer, opener) {
	new Effect.BlindUp(closer, {duration: 0.6, queue: 'front' });
	new Effect.BlindDown(opener, {duration: 0.6, queue: 'end' });
}

//highlight items in video list on rollover
function highlightItem(object) {
  if (object.className == 'item') {
	object.className = 'item item_over';
	}else{
	object.className = 'item';
  }
}


/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['div', 'a'],				// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	findTipObjects : function(objectClass, strClass) {
		var arrList = objectClass.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for ( var i = 0; i < arrList.length; i++ )
        {
        // if class found
        if ( arrList[i].toUpperCase() == strClassUpper )
           {
           // remove array item
           // arrList.splice(i, 1);
           // decrement loop counter as we have adjusted the array's contents
		   return true;
           i--;
           }
		}
	},
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				if(current[j].className == 'info'||current[j].className == 'lg_info'){
					addEvent(current[j],'mouseover',this.tipOver);
					addEvent(current[j],'mouseout',this.tipOut);
				}
				if(sweetTitles.findTipObjects(current[j].className, 'tip')){
					addEvent(current[j],'mouseover',this.tipOver);
					addEvent(current[j],'mouseout',this.tipOut);
					current[j].setAttribute('tip',current[j].title);
					current[j].removeAttribute('title');
				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
		this.style.backgroundPosition = '0 0';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",50);
		sweetTitles.updateXY(e);
		this.style.backgroundPosition = '0 -10px';
	},
	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY-0);
		var lt = parseInt(scrX+15);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			if (anch.getAttribute('content')) {
				addy = (anch.getAttribute('content').length > 60 ? anch.getAttribute('content').toString().substring(0,60)+"..." : anch.getAttribute('content'));
			} else {
				addy = '';
			}
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else {
			/*addy = anch.firstChild.nodeValue;*/
		}
		if ( anch.nodeName.toLowerCase() == 'div' ) {
			this.tip.innerHTML = "<p><em>Video Details:</em>"+anch.innerHTML+"</p>";
			if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
				this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+20))+'px';
			} else {
				this.tip.style.left = lt+'px';
			}
		}
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			this.tip.innerHTML = "<p><em>"+anch.getAttribute('tip')+"</em>"+addy+"</p>";
			if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
				this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+20))+'px';
			} else {
				this.tip.style.left = lt+'px';
			}
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight-10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 90 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.90';
			this.tip.style.filter = "alpha(opacity:90)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',pageLoader);


function popitup(url) {
	newwindow=window.open(url,'name','scrollbars=1,height=550,width=350, true');
	if (window.focus) {newwindow.focus()}
	return false;
}
function popupCustom(url,height,width)
{
	var newwindow;
	newwindow=window.open(url,'name','toolbar=0,menubar=0,resizable=0,scrollbars=0,height='+height+',width='+width+', true');
	if (window.focus) {newwindow.focus()}
	return false;
	
}
function hidePopupItem(id) { 
	popup = document.getElementById(id);
	popup.style.display = 'none';
	 
	hideDivStandard('whiteout');
	
	//Effect.Fade('whiteout', {duration:0.2, from:0.75, to:0});
	//document.getElementById('whiteout').style.display='none';
}

function loginRegPop(e, idtip){
 	pageSize = getPageSize(); //pageWidth,pageHeight,windowWidth,windowHeight
	pageScroll = getPageScroll();
	//whiteout = document.getElementById('whiteout');
	document.getElementById('whiteout').style.height = (pageSize[1])+"px";
	document.getElementById('whiteout').style.width = (pageSize[0])-10+"px";
	showDivStandard('whiteout');
	
	Effect.Appear('whiteout', {duration:0.2, from:0, to:0.75}); 

	logRegBox = document.getElementById(idtip);
	logRegBox.style.top =  (pageSize[1] - pageSize[1]/2)/4+pageScroll[1]+"px"; //"100px"
	logRegBox.style.left = (pageSize[0] - 320)/2+"px";
	//document.getElementById('whiteout').style.display='';
	var t = setTimeout("logRegBox.style.display = ''",300);
}


function embed_url(video, image, e){
	html="<a id='close' onclick='hidePopup()'>Close</a><div class='embed_text'><h2>Embed Script</h2><textarea onclick='this.focus();this.select();'>";
	html+="<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='400' height='245' id='memelabs_embed'><param name='movie' value='http://www.memelabs.com/p.swf?v="+video+"&amp;i="+image+"'></param><param name='allowFullScreen' value='true'></param><embed src='http://www.memelabs.com/p.swf?v="+video+"&amp;i="+image+"' type='application/x-shockwave-flash' width='400' height='245' allowFullScreen='true' quality='high'></embed></object>";
	html+="</textarea></div>";
	sendBox = document.getElementById('sendtofriend');
	sendBox.innerHTML =html;
	sendBox.style.position = "absolute";
	sendBox.style.top = getY(e) - 185+"px";
	sendBox.style.left = getX(e) - 360+"px";
	sendBox.style.display = '';
}

function embed_url_new(video_id, playerURL, homeURL, e){
	html="<a id='close' onclick='hidePopup()'>Close</a><div class='embed_text'><h2>Embed Script</h2><textarea onclick='this.focus();this.select();'>";
	html+="<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='511px' height='319px' id='memelabs_embed'>";
	html+="<param name='movie' value='"+playerURL+"?homeURL="+homeURL+"&amp;playerURL="+playerURL+"&amp;video_id="+video_id+"&amp;auto_play=false'></param>";
	html+="<param name='allowFullScreen' value='true'></param>";
	html+="<embed src='"+playerURL+"?homeURL="+homeURL+"&amp;playerURL="+playerURL+"&amp;video_id="+video_id+"&amp;auto_play=false' type='application/x-shockwave-flash' width='511px' height='319px' allowFullScreen='true' quality='high'></embed></object>";
	html+="</textarea></div>";
	sendBox = document.getElementById('sendtofriend');
	sendBox.innerHTML =html;
	sendBox.style.position = "absolute";
	sendBox.style.top = getY(e) - 185+"px";
	sendBox.style.left = getX(e) - 360+"px";
	sendBox.style.display = '';
}

//sends emails when a sale lead is in (from wordpress -> about/contact)
function emailSalesLead(baseUrl)
{
	new Ajax.Request(baseUrl+'/inc.ajax_email_saleslead.php', 
	{
		method: 'get',
		parameters: {}
	});
}	