// Main initialisation
var ds;   // Data Source
var sl;   // Stack Layout

// For shareThis
var shareObject;

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

// Called when page changed on stack layout
function pageChangeCB(_sl) {
	shareObject.properties.url = "http://www.hthsoft.com/?page="+_sl.getPage();
} 
		
function htSetup() {
	
	ds = new DefaultDS(mainpages, []);
	sl = new StackLayout(pageChangeCB,"content", "submenu", ds, []);
		
	var page = getUrlVars()['page'];
	sl.setCurrent(page?page:'cHome');
		
}

// Call back for share this - for debugging only
// cannot change url as it will only take effect on next shareThis button press -
// need to instead set the url when page is actually changed
function shareThisCallback(SharedObject){
	
	//alert("Share This alert: "+SharedObject.properties.title + "\n" + SharedObject.properties.url);
	/*
 	* Return true to show the widget
 	*/
	return true;
};

function switchMainPanel(titleID, contentName, colour) {
		$('.title').hide();
		$(titleID).show();
		$('#mainpanel').css('background-color', colour);
		sl.setCurrent(contentName);
}

// Create functions specific to main pages
function homePageCreate(){
	var segment = '\
		<style>\
			.app {\
				padding: 5px;\
			}\
			/* Textedit styles ... add different styles to here*/\
			p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}\
			p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica; min-height: 14.0px}\
			p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}\
			span.s1 {color: #000dff}\
			ol.ol1 {list-style-type: decimal}\
			ul.ul1 {list-style-type: disc}\
		</style>';
	for (i in homeSubpages) {
		var subpage = 'cHome.'+homeSubpages[i].name; // Distinguished name
		segment += ('<a class="app" href="#" onclick="sl.setCurrent\(\''+
			subpage+
			'\'\);return false;"><img src="'+
			homeSubpages[i].image+
			'"/></a>'
		);
	}
	return segment;
}

function RF_AppCreate() {
	return '\
	<h2 style="margin-left:auto;width:90%;margin-right:auto;text-align:center;">FoosyBall</h2>\
	<div style="/*overflow:auto;*/">\
		<div style="float:left;width:40%;">\
			<p class="p1">FoosyBall is a foosball table soccer simulation game developed for the Iphone/Ipod Touch. Physics is applied extensively to provide a highly realistic simulation from a real world perspective. The ball acts according to the laws of physics and moves at different speeds and in any direction depending on the amount of force applied when hitting the ball and the position of contact between the player and the ball.<span class="Apple-converted-space"> </span></p>\
			<p class="p2"><br></p>\
			<p class="p1">There are two methods of controlling the rods: by touch control and/or motion control (accelerometer). Touch control still operates with motion control to allow CALIBRATION of rods for the angle at which a user holds the device (Iphone/Ipod touch) and to SPIN the rods.<span class="Apple-converted-space"> </span></p>\
			<p class="p2"><br></p>\
			<p class="p1">The game is in 3D, and the table can be viewed/operated from different camera angles (Table layed horizontally/vertically and perspective views) and also a zoom in/out function. When zoomed in the camera follows the ball.</p>\
			<p class="p2"><br></p>\
			<p class="p1">The game can be stopped at any point. Its state is automatically saved so that the game can be resumed when the application is restarted.</p>\
			<p class="p2"><br></p>\
			<p class="p1">A sophisticated scoring mechanism allows you to earn points and free balls for earning further points. Your score can be posted to the online geographically location aware leader board so you can compete against other players/friends in a geographical region or the whole world. Note your geographical location and sign in information (e.g. actual name/email) is kept absolutely private and not displayed with your score.</p>\
			<p class="p2"><br></p>\
			<p class="p1">This game requires the latest iphone/ipod such as 3GS to play optimally. Older devices are playable but sluggish.</p>\
			<p class="p1"><br></p>\
			<!-- <p class="p2"><a href="#" onclick="sl.setCurrent(\'cHome.cRealFoosball.cRF_video\');return false;">Watch Video</a></p> -->\
			<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=327391278&mt=8"><img src="images/App_Store_Badge_EN.png"/></a>\
		</div>\
		<div style="float:left;width:60%;">\
			<img src="images/rf/image1.png"/>\
			<img src="images/rf/image2.png"/>\
			<img src="images/rf/image3.png"/>\
		</div>\
	</div>\
	';
}

var aboutPage = '\
<p class="p1"><br></p>\
<p class="p2">HTHSoft specialises in delivering customised application solutions for mobile platforms: Iphone and Android.<span class="Apple-converted-space"> </span></p>\
<p class="p1"><br></p>\
<p class="p2">With over 20 years of software engineering experience in the telecommunication and finance industries, and extensive experience in internet based applications and systems,<span class="Apple-converted-space">  </span>The HTHSoft team has the skill and competence to help businesses rapidly formulate and develop software solutions that meet and exceed worlds best practise, providing direction, system specifications and/or hands on development.</p>\
<p class="p1"><br></p>\
<p class="p2">For more information, refer to ...</p>\
\
';

var contactPage = '\
<p class="p1"><br></p>\
<p class="p3">For application support, please email to: <a href="mailto:support@hthsoft.com"><i>support@hthsoft.com</i></a></p>\
<p class="p1"><br></p>\
<p class="p3">For all other enquiries, please email to: <a href="mailto:services@hthsoft.com"><i>services@hthsoft.com</i></a></p>\
<p class="p1"><br></p>\
';

var rfVideoPage = '\
<object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/l98aNlZCH0A&hl=en&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/l98aNlZCH0A&hl=en&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object>\
';

var rfSubpages = [
	{ name: "cRF_video", menu: "Video", _class: "", content: rfVideoPage, subpages: null },
	{ name: "cRF_tips", menu: "Playing Tips", _class: "", content: null, subpages: null }
];

var homeSubpages = [
	{ name: "cRealFoosball", menu: "FoosyBall", _class: "", createFn:RF_AppCreate, subpages: rfSubpages, image:"images/foosyballhthsoft.png"},
	{ name: "cFusionCar", menu: "Fusion Car", _class: "", content: "IPHONE Application: Fusion Car - Coming Soon, watch this space.", subpages: null, image:"images/fc_icon384.png"},
	{ name: "cPyramidChallenge", menu: "Pyramid Challenge", _class: "", content: "IPHONE Application: Pyramid Challenge - Coming Soon, watch this space.", subpages: null, image:"images/pc_icon384.png"}
];

// Compute width - given length of array
var homeStyle = 'width:'+String(homeSubpages.length*512+300)+'px;';

// style and _class is optional
// There must be a content or createFn - if there is both content is ignored
var mainpages = [
    { name: "cHome", menu: "Home", _class: "", style:homeStyle, createFn:homePageCreate, subpages: homeSubpages}, // Create function instead of content
    { name: "cServices", menu: "Services", _class: "", content: "Not yet available.", subpages: null}, 
    { name: "cContact", menu: "Contact", _class: "", content: contactPage, subpages: null},
	{ name: "cAbout", menu: "About", _class: "", content: aboutPage, subpages: null}, 
    { name: "cBlog", menu: "Blog", _class: "", content: "Not yet available.", subpages: null}
];
