//config sIFR
var swiss = {
	src: '/domains/jasa.nl_2/fonts/Swiss721_CnItBt.swf'
	,ratios: [8, 1.41, 9, 1.33, 10, 1.35, 15, 1.31, 19, 1.28, 20, 1.27, 28, 1.26, 29, 1.24, 30, 1.25, 40, 1.24, 43, 1.23, 44, 1.24, 64, 1.23, 72, 1.22, 73, 1.23, 115, 1.22, 116, 1.21, 119, 1.22, 121, 1.21, 1.22]
};
sIFR.useStyleCheck = true;
sIFR.activate(swiss);


$(document).ready(function(){

	//change spec box rows
	$("#header div.specbox div.bottom div:even").addClass('lightRow');

	//change tables
	$(".content table[border=1]").addClass('niceTable').attr('cellspacing',0).attr('cellpadding',0);
	//$('.content table.niceTable tr:first-child').addClass('tableHeader');
	$('.content table.niceTable tr').each(function(){
		if($(this).find('h3').text())
			$(this).addClass('tableHeader');
	});
	$('.content table.niceTable tr:odd').not('.tableHeader').addClass('darkRow');
	$('.content table.niceTable tr:even').not('.tableHeader').addClass('lightRow');

	//change image margin
	$("div.article img").each(function(){
		if($(this).attr('align') == 'left')
			$(this).addClass('rightMargin');
		else if($(this).attr('align') == 'right')
			$(this).addClass('leftMargin');
	});

	//change last col
	var f = 0;
	$("div.article_container").each(function(){
		if($(this).find('div.title').text().length == 0)
			$(this).find('div.title').css('display','none');
		if($(this).hasClass('colom'))
			f++;
		else if($(this).hasClass('whole'))
			f = 0;
		if(f == 3)
			$(this).addClass('lastcolom');
	});
	
	//change video link
	u = $("#header div.viewvideo a").attr('href');
	$("#header div.viewvideo a").attr('href',"javascript:popWindow('/domains/pepperboats.nl_2/video.php',480,360);");

	//top and left submenu's
	$("#menu ul li").hover(
		 function(){
			if($(this).children('ul:eq(0)').is(':hidden')){
				$(this).children('a').addClass('hover');
				if($.browser.msie)
					$(this).children('ul:eq(0)').css('left',$(this).offset().left);
				$(this).children('ul:eq(0)').css('display','block');
			}
		 },
		 function(){
			if($(this).children('ul:eq(0)').is(':visible')){
				$(this).children('a').removeClass('hover');
				$(this).children('ul:eq(0)').css('display','none');
			}
		 }
	);
	$("#menu ul ul li:first-child a").css('background-image','none');
	$("#menu ul ul li:last-child a").css('padding-bottom','0');
	
	
	/**
	* sIFR replacements
	*/
	
	/* == Converts color to HEX == */
	var hex = function(N) {
		if(N==null) return "00";
		N = parseInt(N);
		if(N==0 || isNaN(N)) return "00";
		N = Math.max(0, N);
		N = Math.min(N, 255);
		N = Math.round(N);
		return "0123456789ABCDEF".charAt((N - N%16) / 16) + "0123456789ABCDEF".charAt(N%16);
	};
	/* == Converts colors to HEX == */
	var hexed = function(color) {
		if(!color) { return false; }
		if(color.search('rgb') > -1) {
			color = color.substr(4,color.length-5).split(', ');
			color = hex(color[0]) + hex(color[1]) + hex(color[2]);
		}
		color = color.replace('#','');
		if(color.length < 6) {
			color = color.substr(0, 1) + color.substr(0, 1) + color.substr(1, 1) + color.substr(1, 1) + color.substr(2, 1) + color.substr(2, 1);
		}
		return '#' + color;
	};
	
	//do replacements
	$('.article h1,table.niceTable h3,#header h2').each(function(){
		$title = $(this);
		sIFR.replace(swiss, {
								elements: $title
								,wmode: 'transparent'
								,css: [
								  '.sIFR-root { font-size: ' + (parseInt($title.css('fontSize'))) + '; color: ' + hexed($title.css('color')) + '; }'
								  ,'a { text-decoration: none; color: ' + hexed($title.css('color')) + '; }'
								  ,'a:hover { color: ' + hexed($title.css('color:hover')) + '; }'
								]
							});

	});
});

var uid = (
	function(){
		var id=0;
		return function(){
			return id++ ;
		};
	}
)();

//emulate popup function...
function popWindow(u,w,h,popElement){
	if(!popElement){
		e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
		if(e == 'png' || e == 'gif' || e == 'jpg')
			popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><img src=\""+ u +"\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\" /></div>");
		else
			popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><iframe src=\""+ u +"\"  width=\"" + w + "\" height=\"" + h + "\" border=\"0\" frameborder=\"0\"></iframe></div>");
	}else{
		popEl = $("#" + popElement,{overlay:70});
	}

	popEl.modal();
	$("#modalContainer").css('height',h).css('width',w).css('margin-left',(w / 2) * -1); 
}