/**
 * @author arjen
 * 
 * dependancies: jQuery 1.2.x
 * 
 */

$(function(){
	/**
	 * cross browser stuff
	 */	
	
	// correct boxmodel input[type="text"] FF<3
	if ($.browser.mozilla && parseFloat($.browser.version) < 1.9)
		$("body").addClass("FF2");		
	
	// ie6 workarounds for unsupported css
	if ($.browser.msie && parseFloat($.browser.version) < 7) {
		$("body").addClass("IE6");
		$("acronym[title]").addClass('hasTitle'); /* ie6 doesn't support abbr element */
	}
	
	
	/**
	 * anchors (external/popup)
	 * 
	 */
	var oPopWin = null;
	
	$("a[rel='external']").click(function(){window.open(this.href); return false});
	$("a[rel='popup']").click(function(){
		popWin = new PopupWindow();
		popWin.anchor = $(this);
		popWin.width = 500;
		popWin.height = 500;
		if (popWin.spawn())
			return false;
	});


	/**
	 * Superfish
	 */
	
	// genre/maand dropdowns	
	// onchange handler via selectaccessible.js, maar niet voor Safari
	if (document.getElementById('formNieuwsMaandSelector')){
		if (!$.browser.safari) { 
			initSelect('selectMonth'); // note: don't use same name for id & name attributes! (IE)
			$('#formNieuwsMaandSelector #findBtn').addClass('hidden');
			if($('#formNieuwsSeizoenSelector').length > 0)
			{
				initSelect('selectSeizoen'); // note: don't use same name for id & name attributes! (IE)
				$('#formNieuwsSeizoenSelector #findBtn2').addClass('hidden');
			}
		}
	}
});


jQuery.log = function(message) {
	if (window.console) {
		console.debug(message);
	} else {
		alert(message);
	}
};


/**
 * PopupWindow object
 * spwans/handles popup windows
 * 
 * @author arjen
 * 
 * dependancies: jQuery 1.2.x
 */

function PopupWindow() {
	this.width = 500;
	this.height = 500;
	this.container = $(window);
	this.offsetLeft = 0;
	this.offsetTop = 0;
	this.menubar = true;
	this.location = false;
	this.resizable = true;
	this.scrollbars = true;
	this.status = true;
	this.name = 'popupWindow';
	this.url = ''; 
}
PopupWindow.prototype.prepare = function () {
	oAnchor = this.anchor;
	if (typeof oAnchor.data('popWinObject') == 'object') {
		oPopWin = oAnchor.data('popWinObject');
		if (!oPopWin.closed)
			oPopWin.close();	
	}
	sHref = oAnchor.attr('href');		
	
	if (sHref.indexOf('?') > -1)
		sHref += '&';
	else
		sHref += '?';	
	sHref += 'popup=true';
	this.url = sHref;
}
PopupWindow.prototype.spawn = function() {
	this.prepare();
	var x = this.container.width() / 2 - (this.width/2);
    var y = this.container.height() / 2 - (this.hegiht/2);
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	this.offsetLeft = x;
	this.offsetTop = y;
	
	oPopWin = window.open(this.url, this.name, 'width='+this.width+',height='+this.height+',left='+this.offsetLeft+',top='+this.offsetTop);
	
	if (typeof oPopWin != 'undefined') {
		this.anchor.data('popWinObject', oPopWin);
		//popupWindows.push(oPopWin);
		return true;
	}
	return false;
}
