var HELPERS =
{   
    // Make link change display of another element from block to none (and vice versa)
    linkDropDown : function(linkid, dropdownid){
        if(!$(linkid) || !$(dropdownid)) return false;
        $(dropdownid).onclick = function(e){
            /* Cancel Event Propogation*/
            if (!e) var e = window.event;
            e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
        }
        $(linkid).onclick = function(e){         
            /* Cancel Event Propogation*/
            if (!e) var e = window.event;
            e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
            
            var dropdowns = document.getElementsByClassName($(dropdownid).className);
            for(var i = 0; i < dropdowns.length; i++){
                if(dropdowns[i].getAttribute("id") != dropdownid)
                dropdowns[i].style.display = "none";
            }
            $(dropdownid).style.display = $(dropdownid).style.display == "block" ? "none" : "block";
            
            this.blur();
           
            document.onclick = function(){
                 $(dropdownid).style.display = "none";
                 document.onclick = null;             
             }   
             return false;
        }                    
    },
    
    // Smart Text Input (e.g. search fields)
    memorizeTextInput : function(id, newvalue){
        var input = $(id);
        if(!input) return false;          
		if(typeof newvalue != "undefined")
		input.value = newvalue;
        input.oldval = input.value;
        input.onfocus = function(){
			if(this.value == this.oldval)
            this.value = "";
        }
        input.onblur = function(){
            if(this.value == "")
            this.value = this.oldval;
        }
    },
    
    // Click button to move elements from one multi select to another
    selectTransfer : function(controlid, fromselectid, toselectid){
        if(!$(controlid) || !$(fromselectid) || ! $(toselectid)) return false;
        $(controlid).onclick = function(){
            var fromselect = $(fromselectid);
            var toselect = $(toselectid)
            var length = fromselect.options.length;
            for(var i = 0; i < length; i++){
                if(fromselect.options[i].selected){
                    toselect.appendChild(fromselect.options[i]);
                    --length;
                    --i;
                }
            }            
            this.blur();
            return false;
        }
    },
    
    pause : function(millis) 
    {
        date = new Date();
        var curDate = null;
        do { var curDate = new Date(); } 
        while(curDate-date < millis);
    }
};

// domFunction (will load things faster than addEvent can)

function domFunction(f, a)
{
	var n = 0;
	var t = setInterval(function()
	{
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			c = false;
			if(typeof a == 'object')
			{
				for(var i in a)
				{
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					) 
					{ 
						c = true; 
						break; 
					}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}
		if(n >= 60)
		{
			clearInterval(t);
		}
	}, 250);
};  


var RotatingLogos = {
	currentNode: "", 
	init: function(){
		RotatingLogos.currentNode = $("rotating_logos").getChildren()[0];
		setTimeout("RotatingLogos.fadeNext()", 2500);
	},
	fadeNext: function(){
		var FadeOut = new Fx.Style(RotatingLogos.currentNode, "opacity", {duration:500, onComplete: function(){
			RotatingLogos.currentNode.setStyle("display", "none")
			if(RotatingLogos.currentNode.getNext() != null)
				RotatingLogos.currentNode = RotatingLogos.currentNode.getNext().setStyle("display", "block");
			else
				RotatingLogos.currentNode = RotatingLogos.currentNode.getParent().getChildren()[0].setStyles({
					"opacity":"0",
					"display":"block"
					});
				
			var FadeIn = new Fx.Style(RotatingLogos.currentNode, "opacity", {duration:500, onComplete: function(){
				setTimeout("RotatingLogos.fadeNext()", 2500);
			}})
			FadeIn.start(0.25, 1)
			
		}})
		FadeOut.start(1, 0.25);
	}
} 

function enlargePortfolio(){
	$("portfolioflash2").addClass("enlarged");
}

function shrinkPortfolio(){
	$("portfolioflash2").removeClass("enlarged");
}    

function revealForm(formelement, clickelement){
    $(formelement).setStyle('display', 'none');
	$(clickelement).onclick = function(){
		$(formelement).setStyle('display', 'block');
		return false;
	}
} 


var salesform = new domFunction(function(){
	if(!$("salesemail")) return;
	revealForm("salesemail", "salesreveal");
}, "salesemail");

var pressform = new domFunction(function(){
	if(!$("pressemail")) return;
	revealForm("pressemail", "pressreveal");
}, "pressemail"); 

var jobsform = new domFunction(function(){
	if(!$("jobsemail")) return;
	revealForm("jobsemail", "jobsreveal");
}, "jobsemail"); 

var creativeform = new domFunction(function(){
	if(!$("creativeemail")) return;
	revealForm("creativeemail", "creativereveal");
}, "creativeemail");   

var pmform = new domFunction(function(){
	if(!$("pmemail")) return;
	revealForm("pmemail", "pmreveal");
}, "pmemail");   

var salesform = new domFunction(function(){
	if(!$("salesemail")) return;
	revealForm("salesemail", "salesreveal");
}, "salesemail");  

var adminform = new domFunction(function(){
	if(!$("adminemail")) return;
	revealForm("adminemail", "adminreveal");
}, "adminemail");      

var rotatingLogos = new domFunction(function(){
	if(!$("rotating_logos")) return;
     RotatingLogos.init()
}, "rotating_logos") 

var clientlogin = new domFunction(function(){
	if(!$("loginlink")) return;
	$("loginlink").onclick = function(){
		$("clientlogin").toggleClass("over");
		return false
	}
}, "loginlink") 
          
var togglemore = new domFunction(function(){
	if(!$("togglemore")) return;
	$("togglemore").setStyle("display", "block")
	$("togglemorelink").onclick = function(){
		if($("moreinfo").getStyle("display") == "none"){
			$("togglemorelink").addClass("hide");
			$("moreinfo").setStyle("display", "block")
		} else {
			$("togglemorelink").removeClass("hide");
			$("moreinfo").setStyle("display", "none")
		}
		return false;
	}
}, "togglemore")
var pfflash = new domFunction(function(){
	if(!$("portfolioflash")) return;
	swfobject.embedSWF("/swfs/portfolio.swf", "portfolio", "472", "400", "8.0.0", "", {xmlstring: swfxml}, {menu: "false", wmode: "transparent"});
}, "portfolioflash");

var hpflash = new domFunction(function(){
	if(!$("homepageflash")) return;
	swfobject.embedSWF("/swfs/homepage.swf", "hpflashhook", "593", "330", "8.0.0", "", {}, {menu: "false", wmode: "transparent"});
}, "homepageflash")


var clientflash = new domFunction(function(){
	if(!$("clientlist")) return;
	swfobject.embedSWF("/swfs/clients.swf", "clholder", "572", "451", "8.0.0", "", {xmlstring: "/xml/clients.xml"}, {menu: "false", wmode: "transparent"});
}, "clientlist")

              
      
