var iframe;
var iframeHeight;
function createAppFrame() {
	var startPath=contentStartPath+'?ll='+ll;
	var hashPos=String(window.location).indexOf('#');
	if(hashPos>-1 && String(window.location).indexOf('#/')==hashPos){
		startPath=String(window.location).substr(hashPos+1,String(window.location).length-(hashPos+1));
		if(String(startPath).indexOf('?')>-1){
			if(String(startPath).indexOf('ll='+ll)<0){
				startPath+='&ll='+ll;
			}
		}else{
			startPath+='?ll='+ll;
		}
	}
	var src = contentDomain+startPath
	// Append the Iframe into the DOM.
	iframe = $('<iframe id="stash-app-iframe"" src="' + src + '" width="960" height="1000" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" name="stashapp"><\/iframe>').appendTo('#stash-app-frame');
}
function setFrameHeight(h) {	
	if (iframe!=null && !isNaN( h ) && h > 0 && h !== iframeHeight ) {
	  // Height has changed, update the iframe.
	  iframe.height( iframeHeight = h );
	}
}
function receiveMessage(hash) {
	var val=String(hash).split('_');
	switch(val[0]){
		case 'height':
			//iframe resized
			setFrameHeight(Number(val[1]))
		break;
	}
}
function setupHashNavigation() {
	$(function(){
		// Bind the event.
		$(window).bind( 'hashchange', function(){
			// Alerts every time the hash changes!
			window.location.reload();
		})
	});
}
$(function(){
	createAppFrame();
	setupHashNavigation();
});
