/* Set up Main Menus and Bottom Nav Popup */
var globalTimer = new JKow.Timer(70);
var menu = {};
var btm_pop = {};
var btm_pop_info = { 
	about: { 
		linkid: 'btm_nav_about', 
		bg: 'resource/jkow/bg_about_the_company.png',
		size: { width: 358, height: 352 },
		head: 'img/pop_head_about_the_company.png',
		content: "<p>The Port Lincoln Hotel is one of the most significant tourism developments in regional South Australia.  An initiative of the Sarin Group, the $45 million property caters for both leisure and business tourists, blending a resort-like atmosphere with high quality business facilities.</p><p>The hotel is leased and managed by the Hurley Hotel Group, in conjunction with former Adelaide Crows captain Mark Ricciuto and current captain Simon Goodwin.</p>"
	},
	employ: {
		linkid: 'btm_nav_employ',
		bg: 'resource/jkow/bg_employment_opportunities.png',
		size: { width: 369, height: 520 },
		head: 'img/pop_head_employment_opportunities.png',
		content: "<p>Please send a cover letter, including the position/s you are interested in, and CV to:</p><p>General Manager<br />Port Lincoln Hotel<br /><a href=\"mailto:info@portlincolnhotel.com.au\">info@portlincolnhotel.com.au</a><br /><br /><p>Positions vacant<br /><br /><!--<b>Duty Manager</b> Casual 30-35hrs/week, experience essential - 25/03/09<br /><br /><b>Gaming Manager</b> Salary Position 40-45hrs/week - 25/03/09<br /><br /><b>Night Audit</b> Casual 30-35hrs/week - 25/03/09<br /><br /><b>Breakfast Waiter</b> Casual 20-25hrs/week - 25/03/09<br /><br /><b>Bar Staff</b> Casual - must be available nights and weekends - 25/03/09<br />--></p>"
	},
	media: {
		linkid: 'btm_nav_media',
		bg: 'resource/jkow/bg_media_releases.png',
		size: { width: 369, height: 335 },
		head: 'img/pop_head_media_releases.png',
		content: "<p>Media enquiries, including photograph requests, should be directed to:</p><p>Rebecca Somerfield<br />Mercury Public Relations<br /><a href=\"mailto:mercurypr@internode.on.net\">mercurypr@internode.on.net</a></p><p>ph: +61 (0) 408 823 831</p>"
	},
	creative: {
		linkid: 'btm_nav_creative',
		bg: 'resource/jkow/bg_creative.png',
		size: { width: 252, height: 271 },
		head: 'img/pop_head_creative.png',
		content: "<p>Universal One Studio<br />Upstairs 21 Gilbert Place<br />Adelaide, South Australia</p><p><a href=\"http://www.universalone.com.au\" target=\"New Window\">www.universalone.com.au</a></p><p>ph: +61 (8) 8212 9555</p>"
	}
};

/* Bind menus to timer */
function initBindings(m_id){
	menu[m_id].bindToElement(document.getElementById('menu_' + m_id));
	eval("globalTimer.addOnTimerHandler(function() { menu['" + m_id + "'].animstep(); });");
}

/* Bind btm nav to btns */
function initBtmNav(elid, navid){
	var b = document.getElementById(elid);
	eval("b.onclick = function(){ btm_pop['" + navid + "'].show(); };");
}

/* Generate a close button for popups */
function createCloseButton(){
	var cb = document.createElement('img');
	var $ = cb.style;
	cb.src = 'resource/jkow/x_close.gif';
	cb.className = "button-close";
	$.position = 'absolute';
	$.display = 'block';
	$.top = '20px';
	$.left ='30px';
	$.width ='53px';
	$.height ='7px';
	$.cursor = 'pointer';
	return cb;
}

/* Generate a content div for popup */
function createContentDiv(width, height, content){
	var cn = document.createElement('div');
	var $ = cn.style;
	cn.className = "content";
	cn.innerHTML = content;
	$.position = 'absolute';
	$.display = 'block';
	$.top = '100px';
	$.left = '0px';
	$.paddingLeft = '30px';
	$.paddingRight = '30px';
	$.width = (width - 60).toString() + 'px';
	$.height = height.toString() + 'px';
	$.textAlign = 'left';
	$.verticalAlign = 'top';
	$.color = 'white';
	return cn;
}
/* Create a heading for popup */
function createHeading(bg, width, height){
	var hd = document.createElement('div');
	hd.className = "heading";
	hd.style.position = 'absolute';
	hd.style.width = width.toString() + 'px';
	hd.style.height = width.toString() + 'px';
	hd.style.top = '64px';
	hd.style.left = '30px';
	hd.style.display = 'block';
	JKow.Wtk.setBackgroundImage(hd, bg);
	return hd;
}

/* Prepare the contents of the windows */
function initWindowElem(i){
	var $bni = btm_pop_info[i];
	var $bnp = btm_pop[i];	
	var cb = createCloseButton(); var $ = cb.style;
	cb.style.left = '30px'; cb.style.top = '15px';
	eval("btm_pop['" + i + "'].addClickRegion( { top: parseInt($.top), left: parseInt($.left), right: parseInt($.left) + parseInt($.width), bottom: parseInt($.top) + parseInt($.height) }, function(){ btm_pop['" + i + "'].hide();});");
	$bnp.element.appendChild(cb);
	var hd = createHeading($bni.head, 200, 16);
	$bnp.element.appendChild(hd);
	var cn = createContentDiv($bni.size.width, $bni.size.height, $bni.content);
	$bnp.element.appendChild(cn);
	$bnp.setSize($bni.size.width, $bni.size.height);
	$bnp.setBackgroundImage($bni.bg);
}

/* Main init */
function init(){
	var menuitems = [
	{ menuid: 'accommodation', caption: 'Accommodation'},
	{ menuid: 'functions', caption: 'Functions'},
	{ menuid: 'sarins', caption: 'Sarins Bar'},
	{ menuid: 'sharkys', caption: 'Sharkys Bar'},
	{ menuid: 'gaming', caption: 'Gaming'},
	{ menuid: 'location', caption: 'Location'},
	{ menuid: 'contact', caption: 'Contact'}
	];
	for (var i in menuitems){
		menu[menuitems[i]['menuid']] = new JKow.Wtk.popupMenuItem(menuitems[i]['menuid'], menuitems[i]['caption']);
		eval("JKow.DOM.onContentReady('menu_" + menuitems[i]['menuid'] + "', function() { initBindings('" + menuitems[i]['menuid'] + "'); });");
	}
	
	for (var i in btm_pop_info){
		var $bni = btm_pop_info[i];
		btm_pop[i] = new JKow.Wtk.Window();			
		eval("JKow.DOM.onContentReady('" + btm_pop[i].element.id + "', function(){ initWindowElem('" + i + "'); }); JKow.DOM.onContentReady('" + $bni.linkid + "', function(){ initBtmNav('" + $bni.linkid + "', '" + i + "'); });");
	}	
	resizeContainer();
	globalTimer.start();
}
JKow.Event.addEvent(window, 'load', function(){ init()});

/* Reposition/size footer */
function getClientSize(){
	var result = {width: 0, height: 0};
	if ((typeof(window.innerHeight) == 'number') && (typeof(window.innerWidth) == 'number')){
		result.height = parseInt(window.innerHeight);
		result.width = parseInt(window.innerWidth);
	} else if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){
		result.height = parseInt(document.documentElement.clientHeight);
		result.width = parseInt(document.documentElement.clientWidth);
	} else if (document.body && document.body.clientHeight && document.body.clientWidth){
		result.height = parseInt(document.body.clietHeight);
		result.width = parseInt(document.body.clientWidth);
	} 
	return result;	
}

function resizeContainer(){
	/* Adjust this if footer height changes */
	var heightOffset = 108;
	var minHeight = 950;
	if(document.getElementById){
		var clientSize = getClientSize();
		if (clientSize.height >= minHeight){
			var d = document.getElementById('footer_wrapper');	
			if (d) d.style.top = (clientSize.height - heightOffset).toString() + 'px';
		}
	}
}
JKow.Event.addEvent(window, 'load', function(){ resizeContainer(); init();});
JKow.Event.addEvent(window, 'resize', function(){ resizeContainer()});


/* rss stuff */
var RSS = (function() {
	this.pipebase = 'http://pipes.yahoo.com/pipes/9oyONQzA2xGOkM4FqGIyXQ/run?&_render=json&_callback=RSS.piper&feed=';
	this.feedItemLimit = 4;
	this.getFeed = function(feed){
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = this.pipebase + feed;
		document.getElementsByTagName("head")[0].appendChild(newScript);
	}
	this.piper = function(feed) {
		var tmp='';
		for (var i=0; (i<feed.value.items.length) && ( i < this.feedItemLimit); i++) {
			tmp+='<div class="title">'+feed.value.items[i].title+'</div>';
			if (feed.value.items[i].description) { tmp+= '<div class="desc">'+feed.value.items[i].description + '</div>'; }
		}
		var container=document.getElementById('rss_events');
		if (container != null){
			container.innerHTML=tmp;
		}
	}
	return this;
})();

