/*
 * $Id: common.js 933 2009-12-15 11:26:53Z alex $
 */
/** Open een popup die automatisch gecentreerd wordt in het midden van je browser venster
 * @param string mypage URL naar pagina die getoont moet worden in de popup
 * @param string myname Naam van het venster dat geopend moet worden
 * @param int w Breedte van het venster in px
 * @param int h Hoogte van het venster in px
 * @param string features Extra parameters die je mee wilt geven aan d popup zoals scrollbars=yes... enz.
 * @return void
 */
function newWindow(mypage,myname,w,h,features) {
	if(screen.width) {
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else {
		winl = 0;wint =0;
	}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = "height=" + h + ",";
	settings += "width=" + w + ",";
	settings += "top=" + wint + ",";
	settings += "left=" + winl + ",";
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

function switchAction(formElement,url1,url2) {
	var action = formElement.form.getAttribute('action');
	if (action == url1) {	formElement.form.setAttribute('action',url2); }
	else { formElement.form.setAttribute('action',url1); }
}

pDomApi.addEvent(window, 'load', function() {
	// Set color for text in title randomly
	var newsTitlesSpan = pDomApi.getElementsByClassName('publicationDate', 'span');
	var newsTitlesA = pDomApi.getElementsByClassName('publicationDate', 'a');

	assignColors(newsTitlesSpan);
	assignColors(newsTitlesA);

});

if (typeof actionAtacher == 'undefined') {
    var actionAttacher = pDomApi.getActionAttacher();
}

actionAttacher.addTagEvent(new PrezentDomApi.TagEvent('li', 'menuTitle', 'mouseover',
	function (e) {
		var img = this.firstChild.firstChild;
		var source = img.src;

		if (source.indexOf('-off.') > 0) {
			source = source.replace('-off.', '-on.');
			img.src = source;
		}
	}
));

actionAttacher.addTagEvent(new PrezentDomApi.TagEvent('li', 'menuTitle', 'mouseout',
	function (e) {
		var img = this.firstChild.firstChild;
		var source = img.src;

		if (source.indexOf('-on.') > 0) {
			source = source.replace('-on.', '-off.');
			img.src = source;
		}

	}
));

function assignColors(newsTitles) {
	var colors = new Array(
			'#005cab',
			'#bf5ea3',
			'#91c73d',
			'#ed3363'
		);

		for (var i = 0; i < newsTitles.length; i++) {
			var random = Math.floor(Math.random() * colors.length);

			if (colors.length < 1) {
				// Repopulate color array
				colors[0] = '#005cab';
				colors[1] = '#bf5ea3';
				colors[2] = '#91c73d';
				colors[3] = '#ed3363';
			}

			newsTitles[i].style.color = colors[random];

			//remove color from the array to prevent doubles
			colors.splice(random, 1);
		}
}

if (typeof sIFR == "function") {
	sIFR.replaceElement(named({sSelector:"h2.pageTitle", sFlashSrc:"js/sifr/fonts/helveticaneue.swf", sColor:"#000000"}));
	sIFR.replaceElement(named({sSelector:"h2.title", sFlashSrc:"js/sifr/fonts/helvetica-bold.swf", sColor:"#000000"}));
	sIFR.replaceElement(named({sSelector:"h3.speakerTitle", sFlashSrc:"js/sifr/fonts/helvetica-bold.swf", sColor:"#000000"}));
	sIFR.replaceElement(named({sSelector:"h3.productTitle", sFlashSrc:"js/sifr/fonts/helvetica-bold.swf", sColor:"#000000"}));
	sIFR.replaceElement(named({sSelector:"div.newsBlock h3", sFlashSrc:"js/sifr/fonts/helvetica-bold.swf", sColor:"#000000"}));
};
