// allows to add js or css file onload
function loadjscssfile(filename, filetype){
		if (filetype=="js"){ //if filename is a external JavaScript file
			var fileref=document.createElement('script')
			fileref.setAttribute("type","text/javascript")
			fileref.setAttribute("src", filename)
		} else if (filetype=="css") { //if filename is an external CSS file
			var fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet")
			fileref.setAttribute("type", "text/css")
			fileref.setAttribute("href", filename)
		}
		
		if (typeof fileref!="undefined")
			document.getElementsByTagName("head")[0].appendChild(fileref)
	}


sfHover = function() {
    var sfEls = document.getElementById("main_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"), "");
        }
    }

    var sfEls = document.getElementById("degrees");
    if (sfEls) {
        sfEls = sfEls.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);

// live chat hidden div
var usePopup = false; // set to false when popup is not opened, change to true when opening, and then set to false again on close.

$(document).ready(function(){
	
	var hForm = '<div id="hiddenFormBG" class="lightboxBG" style="display:none;"></div><div id="hiddenForm" class="lightboxForm" style="display:none;"><iframe id="popup_iFrame" src="" frameborder="0" width="100%" height="" scrolling="no" allowTransparency="true"></iframe></div>';
	
	
	$('#live_chat').click( function() {
		loadjscssfile('/scripts/text.js', 'js'); // js for livechat file
	});
		
	// create hidden div so it doesn't have to live in the template
	$('body').prepend(hForm);
		
	// add class to all links with the class of popupForm.  Will load the page from the href into the popup form.
	$('a.popupForm').click(function() {
			handlePopup($(this));
    });

    // change buckets to be links.
    $('.bucket, .bucket2, .bucket3').each(function(index) {
		
        var link = $(this).children('.learn_more').attr('href');

        // not really necessary, changes pointer in real browsers, not necessary for touch intefaces...
        $(this).css('cursor', 'pointer');

        $(this).click(function() {
			if (usePopup == false)
        		window.location = link;
        });
    });
});

function handlePopup($this) {
	usePopup = true;
	var newForm = new LightBoxForm('hiddenForm', 'hiddenFormBG',$this.attr('href'), $this.attr('fh'), $this.attr('fw') );
	newForm.show();
}
