/*	usemedia.com . joes koppers . 11.2010
	thnx for reading this code */

$(window).load(function() {

	artiFlyer = {
		
		//home:window.location.pathname=='/' || window.location.pathname.indexOf('index')!=-1,
		home:window.location.pathname.indexOf('tentoonstellingen_agenda.php')!=-1,
		
		width:910,
		height:586,
	
		show:function(id,pid) {
			this.div = $('<div>/')
				.attr('id','flyer')
				.click(function() {
					artiFlyer.hide();
				})
				.appendTo('body')
				.show();

			this.embed(id,pid);	
		},
		
		embed:function(id,pid) {
		
			if (this.home && !this.readCookie('flyer-shown')) this.createCookie('flyer-shown',true,.1);
		
			var q = 'mode=normal&exhibition=' + (id || '')+'&photo=' + (pid || '') + '&width=' + this.width + '&height=' + this.height;

			$('<iframe/>')
				.attr('frameborder',0)
				.css({
					width:this.width,
					height:this.height,
					marginTop:Math.max(0,($(window).height() - this.height)/2)
				})
				.attr('src','flyer/embed.php?'+q)
				.appendTo(this.div);
		},
		
		hide:function() {
			this.div.remove();
		},
		
		readCookie:function(name) //from www.quirksmode.org
		{
			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 false;
		},
		
		createCookie:function(name,value,days)
		{
			if (days)
			{
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}		
	}
	
	if (artiFlyer.home && !artiFlyer.readCookie('flyer-shown')) artiFlyer.show();
});
