var SITE = {};

SITE.functionality = {
	screenHeight: 0,
	screenWidth: 0,
	lipHeight: 0,
	lipWidth: 0,
	footerXPos: 0,
	footerYPos: 0,
	footerOffset: 250,
	animate: true,
	slidOut: false,
	animationOn: false,
	animationSpeed: 1000,
	tellafriendOn: false,
	home: false,
	themeDir: '...unknown yet...',
	debug: true,
	
	init: function() {
		//$('body').supersleight();	
		
		this.rejectOld();
		
		$("#mail_ico").bind("click",SITE.functionality.tellafriend);
		$("#print_ico").bind("click",SITE.functionality.printArticle);
				
		this._moveSocialBookmarks();
		$("#clickbox").bind("mouseover", SITE.functionality.showSocialBookmarks);
		$("#clickbox").bind("mouseout", SITE.functionality.hideSocialBookmarks);
		$("#linkbox").bind("mouseover", function(){ $(this).show(); $('#bookmark_ico').addClass('bm-open'); });

		this._equalizeColumns();
		this._customizeNavigation();
		this._removeOverlayImage();
		this._siteQuote();
		this._getScreenVars();
		this._moveFooter(this.animate);
		Cufon.replace('p.quote_grey');
		Cufon.replace('p.quote_red');
		this.flashSite();
	},
	
	rejectOld: function() {
		$.reject({  
		    reject: {  
				all: false, 
				msie5: true,msie6: true
		    },
			display: ['firefox','chrome','opera','safari', 'msie'], // Displays only firefox, chrome, opera and ie
			header: 'Uw browser is niet geschikt voor deze website', // Header of pop-up window  
			paragraph1: 'Deze website maakt gebruik van enkele onderdelen die niet ondersteund worden door uw browser. U kunt met uw huidige browser deze website dan ook niet bekijken.', // Paragraph 1  
			paragraph2: 'Wij raden u aan om een van de volgende browsers te downloaden:', // Paragraph 2  
			close: false, // Allow closing of window  
			closeMessage: '', // Message displayed below closing link  
			closeLink: '', // Text for closing link  
			closeURL: '', // Close URL (Defaults '#')  
			closeESC: false, // Allow closing of window with esc key  
			closeCookie: false, // If cookies should be used to remmember if the window was closed (applies to current session only)  
			imagePath: '/wp-content/themes/ceecee/images/browsers/', // Path where images are located  
			overlayBgColor: '#000', // Background color for overlay  
			overlayOpacity: 0.8, // Background transparency (0-1)  
			fadeOutTime: 'fast' // Fade out time on close ('slow','medium','fast' or integer in ms)  				      
		});	
	},
	
	flashSite: function() {
		var userHasFlash = $.flash.available;
		
		if((userHasFlash)&&(this.home)) {
						
			$('#altContent').flash({
				swf: '/wp-content/themes/ceecee/flash/header/interactieveflashbanner.swf',
				height: 245,
				width: 960,
				menu: "false",
				scale: "noScale",
				allowFullscreen: "false",
				allowScriptAccess: "always",
				wmode: "opaque",
				bgcolor: "#FFFFFF",
				id:"interactieveflashbanner"						
			});		
			
				
			
		} else {
		
			$('#siteheader').addClass('noflash');
			$("#altContent").bind('click', function() {
				window.location = '/';
			});
			
		}
		
		if($("#wie_op_ceecee")) {
			if(userHasFlash) {
				$('#wie_op_ceecee').flash({
					swf: '/wp-content/themes/ceecee/flash/wie-op-de-ceecee/CeeCee.swf',
					height: 700,
					width: 960,
 					params: {   
 						base: '/wp-content/themes/ceecee/flash/wie-op-de-ceecee/'  
 					}					
				});	
			} else {
				$('#wie_op_ceecee').addClass('noflash');
			}		
		}
	
	},
		
	tellafriend: function (oE) {
		if(SITE.functionality.tellafriendOn) {
			$('#tellafriendform').hide(SITE.functionality.animationSpeed);
			SITE.functionality.tellafriendOn = false;
		} else {
			$('#tellafriendform').show(SITE.functionality.animationSpeed);
			SITE.functionality.tellafriendOn = true;
		}
		return false;
	},
	
	printArticle: function () {
		window.print();
		return false;
	},
	
	_siteQuote:function() {
		var quote = $('#quotewrapper').html();
		$('#headerlipje').html(quote);
		$('#quotewrapper').remove();		
	},
	
	_customizeNavigation: function() {
		$('#navigationlist').find('li:last').css({background: 'none'});
	},
	
	_equalizeColumns: function() {
		var pMaxH = $('.innerwrapper').height();
		$('#sidebar').height(pMaxH);
	},
	
	_removeOverlayImage: function() {
		$("img").each(function() {
			var source = $(this).attr("src");
			var overlay = strpos(source, 'overlay');
			if(overlay) {
				$(this).hide();
			}
		});
	},	
	
	_moveSocialBookmarks: function() {
		var socialBookmarks = $('.social_bookmark').html();
		var bookmarkTitle = $('.social_bookmark em').html();
		
		if(socialBookmarks) {
			$('#clickbox').append('<p><a id="bookmark_ico" href="#" class="ico">'+bookmarkTitle+'</a></p><div id="linkbox">'+socialBookmarks+'</div>');
			$('.social_bookmark').remove();
			$('#linkbox em').hide();
			$('#linkbox br').hide();
			$('#linkbox').hide();
		}
	},	
	
	showSocialBookmarks: function() {
		var bookmarksMenu = $('#linkbox');
		
		//if(bookmarksMenu && bookmarksMenu.is(":visible")) {
		//	bookmarksMenu.show();
		//	$('#clickbox .ico').removeClass('bm-open');
		//	return false;
		//} 
		
		if(bookmarksMenu && !bookmarksMenu.is(":visible")) {
		//	bookmarksMenu.fadeIn('400');
			bookmarksMenu.show();
			bookmarksMenu.find('br').hide();
			$('#clickbox .ico').addClass('bm-open');
			
		//	return false;
		}
	},
	
	
	hideSocialBookmarks: function() {
		var bookmarksMenu = $('#linkbox');

			bookmarksMenu.hide();
			$('#clickbox .ico').removeClass('bm-open');
			return false;
	},
	
	reposition: function() {
		this._getScreenVars();
		this._moveFooter(false);
	},
	
	_getScreenVars: function() {
		this.screenHeight = document.body.offsetHeight;
		var wrapperOffset = $("#wrapper").offset();
		this.screenWidth = $("#wrapper").width() + wrapperOffset.left;
				
		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
			this.screenWidth++; /* just a little pixelcorrection for Firefox ;-) */
		}
											
		this.lipHeight = $("#sitelipje").height();
		this.lipWidth = $("#sitelipje").width();
	},
	
	evaluateCoords: function( pPageX ) {
		if (pPageX>=this.footerXPos) {
			this._slideOutFooter();
		}
		if (pPageX<this.footerXPos) {
			this._slideInFooter();
		}		
	},
	
	_moveFooter: function(animate) {
		var yPos = this.screenHeight - this.lipHeight;
		var xPos = (this.screenWidth - this.footerOffset) + 20;
		if (animate) {
			$("#sitelipje").animate({top: yPos, left: xPos}, SITE.functionality.animationSpeed);
		} else {
			$("#sitelipje").css({top: yPos, left: xPos});		
		}
		this.footerXPos = xPos;
		this.footerYPos = yPos;
		
		this.slidOut = false;
		this.animationOn = false;
	},
	
	_slideOutFooter: function() {
		if((!this.slidOut)&&(!this.animationOn)) {
			this.animationOn = true;
			this.slidOut = true;
			this.wait = true;
			setTimeout("SITE.functionality._waitOver()",10000);
			this.trace ('moveOut!');
			newX = this.footerXPos + this.footerOffset;
			$("#sitelipje").animate({left: newX}, SITE.functionality.animationSpeed, SITE.functionality.animationOver);
		}
	},
	
	_slideInFooter: function() {
		if((this.slidOut)&&(!this.animationOn)&&(!this.wait)) {
			this.animationOn = true;
			this.slidOut = false;
			this.trace ('go back!!!');
			$("#sitelipje").animate({left: this.footerXPos}, SITE.functionality.animationSpeed, SITE.functionality.animationOver);
		}
	},
	
	_waitOver: function() {
		SITE.functionality.wait = false;
		SITE.functionality.trace('wait is over!');
		SITE.functionality._slideInFooter();
	},
	
	animationOver: function() {
		SITE.functionality.animationOn = false;
		SITE.functionality.trace ('this.animationOn ' + SITE.functionality.animationOn);
		
	},

	trace: function (trace) {
		if (SITE.functionality.debug) {
			if(typeof console =='object') {
				if(typeof trace =='string' || typeof console.dir !='function'){
					console.info("Trace: "+trace);
				}else{
					console.dir(trace);
				}
			}
		}
	}
};
