/**
 * @author Nick Verbeck
 */
MapSearchVideo = Class.create();
MapSearchVideo.prototype = {
	initialize: function(){
		Event.observe(window, 'load', this.onLoad.bindAsEventListener(this));
		this.window = null;
	},
	onLoad: function(pEvent){
		var element = $('MapSearchTopControls');
		var wrapper = new Element('div'); 
		wrapper.innerHTML = '<div id="MapSearchDemo">Map Tools Showcase</div>';
		element.appendChild(wrapper.down());
		Event.observe('MapSearchDemo', 'click', this.onClick.bindAsEventListener(this));
		
		if (this.checkCookie()) {
			this.onClick(pEvent);
		}
	},
	onClick: function(pEvent){
		if (this.window == null) {
			var windowHTML = '<object width="600" height="350">'+
			'<param name="movie" value="/flash/ebby_map_ad.swf" />'+
			'<embed src="/flash/ebby_map_ad.swf" type="application/x-shockwave-flash" width="600" height="350"></embed>'+
			'</object>';
			
			try {
				this.window = new MapSearch.GUI.Window.Window('New Map Tools Showcase');
				this.window.setHTML(windowHTML);
				this.window.setDim(600,350);
				this.window.showCenter();
			} catch (e) {
			}
		} else {
			this.window.showCenter();
		}
	},
	checkCookie: function(){
		var value = this.getCookie('MapSearchDemoViewed');
		if(value === false){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+7);
			document.cookie = "MapSearchDemoViewed=True;expires="+ exdate.toGMTString();
			return true;
		} else {
			return false;
		}
	},
	getCookie: function(c_name){
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1){ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return false;
	}
}
MapSearchVideoObj = new MapSearchVideo();
