﻿initOnload();

function initOnload(){		
    addEvent(window, 'load',initRollovers);
}

var browser = navigator.appName;
var IE = "Microsoft Internet Explorer";
var vendor = navigator.vendor;
var safari = "Apple Computer, Inc.";
var imagePath = "/_layouts/images/cctb/";
var classAttribute = classAttr();   //Get the appropriate class attribute to set. IE and Firefox use different attributes for class in the DOM.

/**** Begin image rollover funtion ****/
/* Function to initalize rollover */
function initRollovers(){	
	var rollovers = getElementsByClass("rollover",null,null);	//Get elements with a class of "rollover"
	
	if (rollovers.length > 0){		//If there is at least one element with a class "rollover"
		for(var i=0;i<rollovers.length;i++){	//Loop through all elements with class "rollover"
			addEvent(rollovers[i],"mouseover",rollover);	//Attach mouseover event
			addEvent(rollovers[i],"mouseout",rollover);	//Attach mouseout event
		}		
	}
}

// This can be used for rollovers that are NOT transparent PNGs. In IE, transparent PNGs are replaced in the DOM with clearpixel.gif, so grabbing the src attribute
// in IE will only return clearpixel.gif, not the actual image src that we want to swap with its on/off state.
// This function grabs the src attribute and replaces "off" with "on" (for mouseover) or "on" with "off (for mouseout) in the attribute string. KM
function rollover(event) {
	var etype = event.type;
	var imgSrc = getImgSrc(this);
	var newImgSrc;
	
	if (etype == "mouseover"){
	    newImgSrc = imgSrc.replace("off.","on.","gi");
		this.setAttribute("src",newImgSrc);
	}
	
	else if (etype == "mouseout") {
	    newImgSrc = imgSrc.replace("on.","off.","gi");
		this.setAttribute("src",newImgSrc);
	}
}

function rolloverInline(imgId,type) {
	var imgObj = $(imgId);
	var imgSrc = getImgSrc(imgObj);
	var newImgSrc;	

	if (type == 'over'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}

	

	else if (type == 'out') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}
}
/***** End image rollover funtion *****/

/***** Begin tab change functions *****/
function initTabbing(){	
	var tabs = getElementsByClass("tab",null,null);	//Get elements with a class of "tab"
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
	
	if (tabs.length > 0){		//If there is at least one element with a class "tab"
		for(var i=0;i<tabs.length;i++){	//Loop through all elements with class "tab"
			addEvent(tabs[i],"click",tabClick);	//Attach click event
		}		
	}
}

function tabClick(event){    
    var tabs = getElementsByClass("tab",null,null);	//Get tabs
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
    	
	for(var t=0;t<tabs.length;t++){ //Loop through all tabs
	    var tabObj = tabs[t];
	    var tabSectionObj = tabSections[t];
	    	    
	    if(tabObj == this){ //Change clicked tab on
            tabObj.setAttribute(classAttribute, "tab selected");
            tabSectionObj.style.display = "block";
	    }
	    else {	//Change other tabs off	        
            tabObj.setAttribute(classAttribute, "tab");
            tabSectionObj.style.display = "none";		    
	    }
	}
}

/***** End tab change functions *****/

/***** Begin showInputWidget function *****/
function showInputWidget(id){
    var inputBar = $(id);
    
    if(inputBar.style.display == "block"){
        inputBar.style.display="none";
    }
    else {
        inputBar.style.display="block";
    }
}
/***** End showInputWidget function *****/

/***** Begin pop up functions *****/
function popWindow(href,title,sb,width,height) {
	window.open(href,title,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+ sb +",resizable=0,width="+ width +",height="+ height +",top=150,left=100");
}
/***** End pop up functions *****/

/***** Begin clear value functions *****/
function initClearValue(){	
	var input = getElementsByClass("clear-value",null,null);
	
	if (input.length > 0){
		for(var i=0;i<input.length;i++){
		    if((input[i].value == "Link (URL)") || (input[i].value == "http://www.example.com")){
		        var currentClass = input[i].getAttribute(classAttribute);
		        input[i].setAttribute(classAttribute, currentClass + " gray-out");
			    addEvent(input[i],"click",clearValue);
			    addEvent(input[i],"focus",clearValue);
			}
		}		
	}
}

function clearValue(){    
    this.value = "";
	removeEvent(this,"click",clearValue);
	removeEvent(this,"focus",clearValue);
	
	//Remove the class that also sets the style for the input before the value is cleared.
    var classValue = this.getAttribute(classAttribute);
    var newClassValue = classValue.replace('clear-value gray-out','','gi');
    this.setAttribute(classAttribute, newClassValue);
}
/***** End clear value functions *****/

/***** Begin resize column function *****/
function resizeColumns(){
    var lc = "content-left";
    var rc = "content-right";
    var buttons = getElementsByClass("builder-buttons",null,null);
    var lcH = null;
    var rcH = null;
    
    if($(lc)){
        lcH = getHeight(lc);
        rcH = getHeight(rc);
        
        if (lcH >= rcH){
            buttons[0].style.float = "none";
            buttons[0].style.clear = "both";
            buttons[0].style.width = "100%";
            $(rc).style.height = eval(lcH + 1)+"px";
        }
    }
    
}
/***** End resize column function *****/
