
var fixed = 0;
var protector;

function init(){
	
	fix();
	fix_png();
	protector = new dwProtector(); 
	
	var ToolTips = new Tips($$('.mootip'), {
    	
    	showDelay: 250,
    	
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: true}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
		
	});
	
	if($defined($('news'))){
		
		var Fx1 = new Fx.Style('news', 'color', {duration:1000, onComplete: function(){ Fx2.start('#8B8E93', '#000000'); }});
		var Fx2 = new Fx.Style('news', 'color', {duration:1000, onComplete: function(){ Fx1.start('#000000', '#8B8E93'); }});
		Fx1.start('#000000', "#8B8E93");
		
	}
	
	protector.protect();
}

function fix_png(){
	if(!fixed){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if ((version >= 5.5) && (document.body.filters)){
			var png_images = $$('.pngfix');	
			png_images.each(function(element) {
				var img = $(element);
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
			});
		}
	}
	fixed = 1;
}

var wintype = 800;

function fix(){
	fixed = 1;
	//	check size
	win_height = window.getHeight();
	win_width = window.getWidth();
	if(win_height < 680){
		//	1024 x 768
		wintype = 768;
	} else if(win_height < 850){		
		wintype = 900;
	} else {
		//	1280 x 1024 >
		wintype = 1024;
	}
	//	load images
	var rszimgs = $$('.rszimg');
	rszimgs.each(function(element){
		if(element.getAttribute('src') != element.getAttribute('rszsrc')){
			var classes = element.getProperty('class');
			classes = classes.replace("rszimg", "");
			$(element.getAttribute('replace_id')).setHTML('<img src=\"http://www.ruudvanderpeijl.com/page=site.rsz/wintype='+wintype+'/chain='+element.getAttribute('chain')+'/img='+escape(element.getAttribute('rszsrc'))+'\" border=\"0\" class=\"protect '+classes+'\">');
			$(element.getAttribute('replace_id')).setStyle('background', '');
		}
	});
}

function swap_image(element, chain, image){
	element.setHTML('<img src=\"http://www.ruudvanderpeijl.com/page=site.rsz/wintype='+wintype+'/chain='+chain+'/img='+escape(image)+'\" border=\"0\" class=\"protect pageimage\">');
	element.setStyle('background', '');
	protector.protect();
}

function load_video(element, video){
	var s = new SWFObject("http://www.ruudvanderpeijl.com/swf/mediaplayer.swf",element, "415", "311","7");
	s.addParam("allowfullscreen","true");
	s.addVariable("file",video);
	s.addVariable("displayheight","311");
	s.addVariable("backcolor","0x000000");
	s.addVariable("frontcolor","0xffffff");
	s.addVariable("lightcolor","0xa0a0a0");
	s.addVariable("width","415");
	s.addVariable("height","311");
	s.addVariable("overstretch","false");
	s.addVariable("autostart","true");
	s.addVariable("repeat", "false");
	s.addVariable("shuffle", "false");
	s.write(element);
}

function open_submenu(in_menu){
	var submenus = $$('.submenu');
	submenus.each(function(element){
		if(element.id != 'submenu_'+in_menu){
			element.setStyle('display', 'none');	
		}	
	});
	if($defined($('submenu_'+in_menu))){
		$('submenu_'+in_menu).setStyle('display', 'inline');
	}
}

//protector class   
var dwProtector = new Class({   
       
    //initialization   
    initialize: function(options) {     
    },   
       
    //a method that does whatever you want   
    protect: function() {  
    	elements = $$('.protect');
        //for each image that needs be protected...   
        elements.each(function(el) {   
            //get the element's position, width, and height   
            var size = el.getCoordinates();   
            //create the protector   
            var p = new Element('img', {   
                src: 'http://www.ruudvanderpeijl.com/img/empty.gif',   
                width: size.width,   
                height: size.height,   
                styles: {   
                    'z-index': 10,   
                    'left': size.left + 'px',   
                    'top': size.top + 'px',   
                    'position': 'absolute'  
                }   
            }).inject($(document.body),'top');   
        },this);   
           
    }   
});  

window.addEvent('load', function(){ 
	init(); 
});
