// +------------------------------------------------------------------+
// | JavaScript version 1.0                                           |
// +------------------------------------------------------------------+
// | general.js – Some standard functions used in the CMS cleint      |
// |              side. Script is loaded in template by parser.       |
// +------------------------------------------------------------------+
// | Copyright (c) 2008 MultiMove                                     |
// +------------------------------------------------------------------+
// | Authors: S.F.Beck <sander@multimove.nl>     					  |
// +------------------------------------------------------------------+


/**
 * The load function
 * 
 * @return void
 */
function doLoad( bgImage ){
	try{
		//make a random number, prevents caching!
		var randomnumber=Math.floor(Math.random()*9999999999999999999);
		
		// Initiate flash background
		var flashvars = {	
			bitmap: ""+bgImage
		}
		
		var params = {                   
				allowfullscreen:"false", 
				allowscriptaccess:"sameDomain",
				wmode:"transparent",
				quality:"high",
				scale:"noscale",
				salign:"lt",
				align:"middle",
				bgcolor:"#000000"				
		}
		var attributes = {
				id:"backgroundPlayer",  
				name:"backgroundPlayer"
		}
		
		swfobject.embedSWF(BASE_URL+"flash/body_bg.swf?233="+randomnumber, "flashcontainer", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
	} catch(e){ }
}

function showpopup(){
	document.getElementById('popup_window_bg').style.display = 'block';
	timer = setInterval('fadeIn()', 5);
}

/**
 * Make pop-up windows
 * 
 * @return void
 */
function popup( url, width, height )
{
	var iLeft = (screen.width - width) / 2 ;
	var iTop  = (screen.height - height) / 2 ;

	var sOptions = "resizable=yes,dependent=yes,scrollbars=yes," ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	window.open( url, "FCKBrowseWindow", sOptions ) ;
}


/**
 * Clear textfields preset text and turn to black
 * 
 * @return void
 */
function clearText(thefield, onfocus)
{
	if(onfocus && thefield.value == thefield.defaultValue)
	{
		thefield.value = '';
		thefield.style.color = '#000000';
	}
	if(!onfocus && thefield.value == '')
	{
		thefield.value = thefield.defaultValue;
		thefield.style.color = '#cccccc';
	}
}


var PositionX = 100;
var PositionY = 100;
var defaultWidth  = 100;
var defaultHeight = 100;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
var optNN='scrollbars=no, status=yes, width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no, status=yes, width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle,imageTitle2){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=10+document.images[0].width;');
		writeln('height=59+document.images[0].height;');
		
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');
		writeln('window.innerWidth=document.images["George"].width;');
		writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle2+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle(); self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src="'+imageURL+'" alt="'+imageTitle+'" onClick="window.close();" style="display: block; cursor: pointer;"></body></html>');
		close();
	}
}


/**
 *
 */
function popupGalleryImage(galleryTitle, imageBrowserUrl, imageDesc)
{
	var PositionX = 0;
	var PositionY = 0;
	var defaultWidth  = 250;
	var defaultHeight = 250;
	
	if (parseInt(navigator.appVersion.charAt(0))>=4)
	{
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
	}
	
	var optNN='scrollbars=no, status=yes, width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no, status=yes, width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	
	if (isNN){imgWin=window.open(imageBrowserUrl,'gallery',optNN);}
	if (isIE){imgWin=window.open(imageBrowserUrl,'gallery',optIE);}
}


/**
 *
 */
function mailinglistXmlhttpPost(url, query)
{
    var xmlHttpReq = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', url, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
      if(self.xmlHttpReq.readyState == 4)
      {
        var type = self.xmlHttpReq.responseText.split('|');
        
        switch(type[0])
        {
          default:
            alert(type[1]);
            break;
          
          case 'succes=2':
            alert(type[1]);
            document.getElementById('mailinglist_unsubscribe').style.display = 'none';
            document.getElementById('mailinglist_content').style.display = 'block';
            break;
          
          case 'succes=1':
            document.getElementById('mailinglist_content').style.display = 'none';
            document.getElementById('mailinglist_succes').style.display = 'block';
            break;
          
          case 'error=3':
          case 'error=2':
            alert(type[1]);
            break;
          
          case 'error=1':
            document.getElementById('mailinglist_content').style.display = 'none';
            document.getElementById('mailinglist_error').style.display = 'block';
            document.getElementById('error_text').innerHTML = type[1];
            break;
        }
      }
    }
    
    self.xmlHttpReq.send(query);
}


function initPlayer() {	
	
	try{
		var flashvars = {
				file: BASE_URL+"flash/playlist.xml", 
				autostart:"false",
				controlbar:"hidden", 
				repeat:"true",
				icons:"false",
				backcolor:"000000",
				frontcolor:"E1E1E1",
				lightcolor:"cf55b3",
				image: BASE_URL+"flash/preview.jpg"
		}
		var params = {                   
				allowfullscreen:"false", 
				allowscriptaccess:"always",			
				quality:"high",
				bgcolor:"#000000"	
		}
		var attributes = {
				id:"player1",  
				name:"player1"
		}
		
		swfobject.embedSWF(BASE_URL+"flash/player.swf", "playerholder", "234", "223", "9.0.115", false, flashvars, params, attributes);	
	} catch(e){ }
}


function makeFonts() {
	
	try{
		var MyriadProCond = {
		  src: BASE_URL+'flash/MyriadProCond.swf'
		 
		};
	
		// sIFR.useStyleCheck = true;
	   sIFR.activate(MyriadProCond);  
	   sIFR.replace(MyriadProCond, {
		  selector: 'h1'
		  ,wmode: 'transparent'
		  ,css: ['.sIFR-root {text-align: left; color:#ffffff; font-size:24px;}']
		  ,selectable: true
		});	
	
		sIFR.replace(MyriadProCond, {
		  selector: 'h2'
		  ,wmode: 'transparent'
		  ,css: ['.sIFR-root {text-align: left; color:#042e48; font-size:24px; }']
		  ,selectable: true
		});	
		
		sIFR.replace(MyriadProCond, {
		  selector: 'h3'
		  ,wmode: 'transparent'
		  ,css: ['.sIFR-root {text-align: left; color:#ffffff; font-size:19px; }']
		  ,selectable: true
		});	
		
		sIFR.replace(MyriadProCond, {
		  selector: 'h4'
		  ,wmode: 'transparent'
		  ,css: ['.sIFR-root {text-align: left; color:#ffffff; font-size:20px; margin: 0; }', '.sIFR-root a {text-decoration: none; color: #cecece; }', '.sIFR-root a:hover {color: #ffffff; }', '.submenu_on {color: #ffffff; }']
		  ,selectable: true
		});	
	} catch(e){ }
}

var news_delay_active = 'no';
var announcement = 1;
function announcementReplace (id){
	try{
		if( id=='next' ){
			if( announcement < 4 )
				announcement = announcement+1;				
			id = announcement;
		}			
		if( id=='prev' ){
			if( announcement > 1 )
				announcement = announcement-1;
			id = announcement;
		}
		
		if(news_delay_active == 'no')
		{
			var f = function() {news_delay(id); };
			news_delay_active = 'yes';
			setTimeout(f, 500);
		}
	}catch(e){}
}
 
 
function news_delay(id){
	//hide all accouncements
	for(var i=1; i<=4; i++){			
		document.getElementById("announcement"+i).style.display = "none"; 
		document.getElementById("but_headlines"+i).src = BASE_URL+"images/layout/menu/but_headlines_"+i+"_off.gif"; 
	}
			
	document.getElementById("announcement"+id).style.display = "inline";
	document.getElementById("but_headlines"+id).src = BASE_URL+"images/layout/menu/but_headlines_"+id+"_on.gif";
	makeFonts();	
	//announcement = id;
			
	news_delay_active = 'no';
}


var speed = 20;
var footervisible = true;
var height = 140;
function hidefooter (){
	
	//The footer is out so close it
	if( footervisible ) 
	{	
		height -= speed; 
		document.getElementById('footer').style.height = height+"px"; 
		if ( height > 30 ){
			//document.getElementById('footercontainer').style.display = "none";
			 setTimeout('hidefooter()', 5); 
		}
		else
		 {
			 footervisible = false;	
			 document.getElementById('footer_slidein').style.backgroundImage="url("+BASE_URL+"images/layout/but_slideout.gif)";
		 }
	}
	
	//The panel is in so open it
	else{
		height += speed; 
		document.getElementById('footer').style.height = height+"px"; 
		if ( height < 140 )
			 setTimeout('hidefooter()', 5); 
		else
		 {
			footervisible = true;
			 document.getElementById('footer_slidein').style.backgroundImage="url("+BASE_URL+"images/layout/but_slidein.gif)";
		 }
	}
}


/**
 *
 */
function strpos(haystack, needle, offset)
{
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

/**
 *
 */
function loadVideo(url, width, height, backcolor, frontcolor, lightcolor)
{
	//Initiate video player
	var so = new SWFObject(BASE_URL+"flash/videoplayer.swf", "videoplayer", width, height, "9");
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('wmode', 'transparent');
	so.addVariable('flashvars', '&amp;file='+url+'&amp;autostart=true&amp;repeat=true&amp;backcolor='+backcolor+'&amp;frontcolor='+frontcolor+'&amp;lightcolor='+lightcolor);
	so.write("video_player");
}

/**
 *
 */
function initShadowbox(backcolor, frontcolor, lightcolor)
{
	try { Shadowbox.init(backcolor+';'+frontcolor+';'+lightcolor); }
	catch(e) { alert(e.toString()); }
}
