var root = $webroot || "/";

var sIFRConfig = {
	init:function(){
		while(this.profiles.length) {
			var profile = this.profiles.pop()
			sIFR.activate(this.fonts[profile.font]);
			sIFR.replace(this.fonts[profile.font], profile.params);
		}
	},
	fonts:{
		albertbold:{
			src: root + 'includes/swf/albertbold.swf',
			ratios:[10,1.32,16,1.27,23,1.23,24,1.21,25,1.22,31,1.21,38,1.2,42,1.19,43,1.2,62,1.19,66,1.18,67,1.19,113,1.18,114,1.17,119,1.18,120,1.17,1.18]
		}
	},
	profiles:[{
			font:'albertbold',
			params:{
				selector: 'DIV.content-side DIV.article H1',
			    css: {'.sIFR-root': {'font-size':'28px', 'leading':-1 ,'color': '#0b497d', 'background-color' : '#f3f3f5', 'kerning':'true' }}
		    }
		},{
			font:'albertbold',
			params:{
				wmode: 'transparent',
				selector: 'DIV.content-side DIV.article-home H1',
			    css: {'.sIFR-root': {'font-size':'30px', 'leading':-5 ,'color': '#FFFFFF', 'kerning':'true' }}
		    }
		},{
			font:'albertbold',
			params:{
				wmode: 'transparent',
				selector: 'DIV.gallery-home H1',
			    css: {'.sIFR-root': {'font-size':'30px', 'leading':-5 ,'color': '#ffffff', 'background-color' : '#b696bd', 'kerning':'true' }}
		    }
		},{
			font:'albertbold',
			params:{
				selector: 'DIV.hero-copy DIV.article H1',
			    css: {'.sIFR-root': {'font-size':'28px', 'leading':-1 ,'color': '#FFFFFF', 'background-color' : '#0b497d', 'kerning':'true' }}
		    }
		}]
};

/* Insert Link Arrows */
var linkArrows = function() {
	var toArrow = document.createElement("SPAN");
	var backArrow = document.createElement("SPAN");
	toArrow.className = "arrow";
	toArrow.innerHTML = "&#8250;&#8250;";
	backArrow.className = "arrow-back";
	backArrow.innerHTML = "&#8249;&#8249;";
	var anchors = document.getElementsByTagName("a");
	var goToRegExp = RegExp("(^|)go-to(|$)");
	var goBackRegExp = RegExp("(^|)go-back(|$)");
	for (var j=0; j < anchors.length; j++) {
		if(goToRegExp.test(anchors[j].className)){
			anchors[j].parentNode.insertBefore(toArrow.cloneNode(true), anchors[j].nextSibling);
		}
		if(goBackRegExp.test(anchors[j].className)){
			anchors[j].parentNode.insertBefore(backArrow.cloneNode(true), anchors[j]);
		}
	}	
};

var hoverClass = function(){
	if (window.ie6) {
		var ul_array = document.getElementsByTagName("ul");
		for (var i=0; i<ul_array.length; i++) {
			if(ul_array[i].className.indexOf('hover') >= 0) {
				sethoverClass(ul_array[i]);
			}
		}
	}
};
		
var sethoverClass = function(list){
	for (var k=0; k<list.childNodes.length; k++) {
		node = list.childNodes[k];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className+=" over";
			}
			node.onmouseout=function() {
				this.className=this.className.replace(" over", "");
			}
		}
	}
}

var evaluationForm = {
	init:function(){
		this.form = document.getElementById("evaluation-form");
		if(!this.form) return;
		for (var k=0; k<this.form.elements.length; k++){
			if(hasClass(this.form.elements[k], "other-radio")){
				this.form.elements[k].onclick = this.otherClick;
				this.otherClick.call(this.form.elements[k])
			}
			else if(this.form.elements[k].getAttribute("type") == "radio") {
				this.form.elements[k].onclick = this.notOtherRadioClick;
			}				
		}
	},
	
	otherClick:function(){
		window[(this.checked ? "addClass" : "removeClass")].call(this, this.parentNode.parentNode, "other-selected")
	},
	
	notOtherRadioClick:function(){
		removeClass(this.parentNode.parentNode, "other-selected")
	}
}

var polaroid = {
	init:function(){
		if(hasClass(document.getElementById("primary"), "random-polaroid")){
			var div_array = document.getElementById("primary").getElementsByTagName("div")
			for (var i=0; i<div_array.length; i++) {
				if(hasClass(div_array[i], "polaroid")){
					var num = Math.floor((Math.random()*10)%5)*8;
					div_array[i].style.paddingTop = num + "px";
				}
			}
		}		
	}
}
	

/* Page Config */
sIFRConfig.init();

window.onload = function(){
	hoverClass();
	linkArrows();
	evaluationForm.init();
	polaroid.init();
}


//Media Player Profiles
var audioProfileSide = {width:180,height:20,usefullscreen:false,showdownload:false,showdigits:false};
var audioProfileLarge = {width:240,height:20,usefullscreen:false,showdownload:false,showdigits:false};
var videoProfileLarge = {width:290,height:183,usefullscreen:true,showdownload:false,showdigits:false};


//Media Player
var MediaPlayer = function(id, opts, obj){
	var options = {
		width:320, 
		height:260,
		file:obj.file,
		showdownload:false,
		showdigits:false,
		enablejs:true,
		javascriptid:id
	};
	for(name in opts){
		options[name] = opts[name];	
	}
	if(obj['image']) {
		options["image"]  = obj.image;
	}
	swfobject.embedSWF(root+"includes/swf/mediaplayer.swf", id, options.width, options.height, "8.0.0", root+"includes/swf/expressInstall.swf", options);
	this.id = id;
};
MediaPlayer.prototype = {
	loadFile:function(obj) { 
		if(!this.movieRef)
			this.movieRef = (navigator.appName.indexOf("Microsoft") != -1 ? window[this.id] : document[this.id]);
		this.movieRef.loadFile(obj); 
	}
};