function connectioncard() {
	$('#connectCard .close').click(function(){
		$('#connectCardOverlay').fadeOut('slow');         
	});
	return null;
}
function showConnectioncard() {
	$('#connectCardOverlay').fadeIn('slow');
}

function setSizeConversion(s) {
	var sURL = _root + "include/ajax_setsizeconversion.asp"
	var sData = "?sizeconversion=" + s;
	
	$.ajax({
		type: "GET",
		url: sURL + sData,
		cache: false,
		async: true,
		success: function(xml){
			window.location.reload();
		}, 
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.responseText);
		}
  	});
}


function detectThinViewport() {
	var wWidth = $(window).width();
	if (wWidth < 1092) {
		$("#some").hide();
	}

	$(window).resize(function () {
		var wWidth = $(window).width();
		if (wWidth < 1092) {
			$("#some").hide();
		} else {
			$("#some").show();
		}
	});
}


function formatPrice(sVal) {
	sVal = Math.round(sVal*100)/100;
	sVal = sVal.toString();
	
	var nPoint = sVal.indexOf(".");
	var dec = sVal.length - nPoint;
	
	if(nPoint == -1) {
		sVal = sVal + ".00";
	} else if (dec == 2) {
		sVal = sVal + "0";
	}
	
	sVal = sVal.replace(/\./, ",");
	return "&euro; " + sVal;
}


function getRadioButtonValue(o) {
	var sVal;

	for(var i=0;i<o.length;i++) 
	{
		if(o[i].checked)
			sVal = o[i].value;
	}
	return sVal;
}


function makeFlashObj(sID, sPath, sWidth, sHeight, sBG){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + sID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + sWidth + '" height="' + sHeight + '">');
	document.write('<param name="movie" value="' + sPath + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="' + sBG + '">');
	document.write('<embed bgcolor="' + sBG + '" src="' + sPath + '" quality="high" id="' + sID + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + sWidth + '" height="' + sHeight + '"></embed>');
	document.write('</object>');
}


function setActiveStyleSheet(title){
	var i, a, main;	
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}


function getActiveStyleSheet() {
	var i, a;	
	for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}	
	return null;
}


function getPreferredStyleSheet() {	
	var i, a;	
	for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) return a.getAttribute("title");
	}	
	return null;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	} else expires = "";	
	document.cookie = name + "=" + value + expires + "; path=/";
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for (var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}	
	return null;
}


window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
 }


window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var tmo;
function waitScroll(){
	clearTimeout(tmo);
	tmo=setTimeout('centerPageOverlay(1)',50)
}

function centerPageOverlay(type){
	var w 		= $('#overlayPage').width();
	var h 		= $('#overlayPage').height();
	var ww		= $(window).width();
	var wh		= $(window).height();
	var top 	= Math.round((wh-h)/2)
	var left 	= Math.round((ww-w)/2)
	
	$('#overlayBG').css({'width' : ww+'px'});
	
	if (type==1){
		var newtop 	= top + $(window).scrollTop();
	}
	else{
		var newtop = top
	}
	$('#overlayPage').animate({
		left : left+'px',
		top : newtop+'px'
	},250)
}


function createPageOverlay(src){
	var w 		= 970,
		h 		= 525,
		pd		= 15,
		ww		= $(window).width(),
		wh		= $(window).height(),
		top 	= Math.round((wh)/2),
		left 	= Math.round((ww)/2),
		dh		= $(document).height();
		nh		= wh
	if (dh>wh){
		nh = dh
	}
	
	$('<div id="overlayPage"></div>').prependTo('body');
	$('<div id="overlayBG"></div>').prependTo('body');
	
	$('#overlayBG').css({
		'width' : ww+'px',
		'height' : nh+'px',
		'opacity' : 0.3
	});
	
	
	$('#overlayPage').css({
		'width' : '1px',
		'height' : '1px',
		'left' : (left-2)+'px',
		'top' : top+'px'
	});
	
	
	$('<div class="divZO"></div>').prependTo('#overlayPage');
	$('<div class="divN"></div>').prependTo('#overlayPage');
	$('<div class="divW"></div>').prependTo('#overlayPage');
	$('<div class="divNW"></div>').prependTo('#overlayPage');
	$('<div class="divClose"></div>').prependTo('#overlayPage');
	$('<div class="divLoading">Loading</div>').prependTo('#overlayPage');
	$('#overlayPage .divZO').css({
		'left' : pd+'px',
		'top' : pd+'px'
	});
	$('#overlayPage .divN').css({
		'height' : pd+'px',
		'left' : pd+'px'
	});
	$('#overlayPage .divW').css({
		'width' : pd+'px',
		'top' : pd+'px'
	});
	$('#overlayPage .divNW').css({
		'height' : pd+'px',
		'width' : pd+'px'
	});
	$('#overlayPage .divLoading').css({
		'left' : pd+'px',
		'top' : pd+'px'
	});
	
	$('#overlayPage .divClose').click(function(){
		closePageOverlay('');
	});
	
	
	var top 	= Math.round((wh-h)/2)
	var left 	= Math.round((ww-w)/2)
	
	$('#overlayPage').animate({
		width : w+'px',
		height : h+'px',
		left : left+'px',
		top : top+'px'
    },
	500, 
	function() {
		$('<iframe src="" frameborder="0" style="width:200px;height:200px;"></iframe>').prependTo(this);
		
		$('#overlayPage iframe').css({
			'width': (w-(pd*2))+'px',
			'height': (h-(pd*2))+'px',
			'top': pd+'px',
			'left': pd+'px'
		});
		
		$('#overlayPage iframe').attr({'src':src+'?iframe=yes'});
	});
}

function closePageOverlay(url){
	
	var ww		= $(window).width();
	var wh		= $(window).height();
	var top 	= Math.round((wh)/2);
	var left 	= Math.round((ww)/2);

	$('#overlayPage').remove();
	$('#overlayBG').remove();
	if (url!=''){
		location.href = url
	}
}



function renderFlash(o){
	$(o).html('');
	
	var options 			= $(o).metadata({type:'attr',name:'options'});
	var sSrc 				= options.src;
	var sImage				= options.image;
	var sType 				= options.type;
	var nWidth 				= options.width;
	var nHeight 			= options.height;
	var sLink 				= options.link;
	var sMediaSkin			= options.skin;
	var bAllowFullScreen 	= options.allowfullscreen;
	var bAutoStart 			= options.autostart;
	var bRepeat				= options.repeat;
	if (bRepeat==undefined){
		bRepeat = 'none'
	}
	if (bAutoStart==undefined){
		bAutoStart			= false
	}
	
	var sSkin				= ''
	//if (sMediaSkin==undefined || sMediaSkin==''){
		//sMediaSkin			= mediastyle
	//}
	//if (sMediaSkin.match('.zip')!=null){
		//sSkin			= (_wwwroot + 'flash/' + sMediaSkin)
	//}
	
	var sPlayerSource		= '';
	var sFlashvars			= '';
	var sParameters 		= '';
	var bAllowScript		= 'always';
	var sAttributes 		= '';
	
	
	var d	= new Date();
	var m   = d.getMinutes();
	var s   = d.getSeconds();
	var ms	= d.getMilliseconds();
	if (ms<10){ms=('00'+String(ms))}else if (ms<100){ms=('0'+String(ms))}else{ms=String(ms)}
	if (s<10){s=('0'+String(s))}else{s=String(s)}
	if (m<10){m=('0'+String(m))}else{m=String(m)}
			
	var rnd	= String(Math.random()*101)
		rnd	= rnd.replace('.','-');
	var id	= ((m+s+ms) + '_' + rnd)
	var nPlayerID = ('mediaplayer' +id);
	
	$(o).prepend('<div id="' +nPlayerID+ '"></div>');
	
	
	if(sType=='flash'){
		sPlayerSource	= _root + sSrc
	  	sFlashvars 		= {autostart:bAutoStart};
	  	sParameters 	= {allowfullscreen:bAllowFullScreen, allowscriptaccess:bAllowScript};

	}
	else if (sType=="flv"){
		sPlayerSource	= _root + 'swf/player.swf'
		sFilename		= _wwwroot + sSrc
		
		if (sImage!=undefined){
			sImageFilename	= _wwwroot + sImage
	  		sFlashvars 		= {file:sFilename,image:sImageFilename,autostart:bAutoStart,link:sLink,skin:sSkin,repeat:bRepeat};
		}
		else{
	  		sFlashvars 		= {file:sFilename,autostart:bAutoStart,link:sLink,skin:sSkin,repeat:bRepeat};
		}
	  	sParameters 	= {allowfullscreen:bAllowFullScreen, allowscriptaccess:bAllowScript};

	}
	else if (sType=="mp3"){
		sPlayerSource	= _root + 'swf/player.swf'
		sFilename		= _wwwroot + sSrc
	  	sFlashvars 		= {file:sFilename,autostart:bAutoStart,type:'sound',link:sLink,skin:sSkin};
	  	sParameters 	= {allowfullscreen:bAllowFullScreen, allowscriptaccess:bAllowScript};
		
	}
	else if (sType=="youtube"){
		sPlayerSource	= sSrc
	  	sFlashvars 		= {autostart:bAutoStart};
	  	sParameters 	= {allowfullscreen:bAllowFullScreen, allowscriptaccess:bAllowScript};
		
	}
	
	if (sPlayerSource!=''){
	  	swfobject.embedSWF(sPlayerSource, nPlayerID, nWidth, nHeight, '9.0.115', false, sFlashvars, sParameters, sAttributes);
	}
	
}
