var minImages = 16; //minimum images required to build app
var maxNumImagesAllowed = 99; //max images to build app
var maxImageWidth = 320; //max to show on page (avoid editing massive images)
var maxImageHeight = 800;
var idealIconWidth = 512;
var idealIconHeight = 512;
var idealTitleWidth = 320;
var idealTitleHeight = 480;
var idealBackgroundWidth = 320;
var idealBackgroundHeight = 480;
var largerThumbnailWidth = "200px";
var previewURL = "../PreviewTool/AppBuilder/index.php";


$(
	function(){
		$("body").ajaxSend( function(c,xhr){
			$( window ).bind( 'beforeunload', function() {
				xhr.abort();
			})
		});
	}
);

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;
}

function createPageLoader() {
	// Create overlay and append to body:
	$('<div id="overlay"/>').css({
		position: 'fixed',
		top: 0,
		left: 0,
		'z-index':10000,
		width: '100%',
		//height: $(window).height() + 'px',
		height: '100%',
		background: 'black url(content/loader_big.gif) no-repeat center'
	}).hide().appendTo('body');
	$('#overlay').fadeTo("def", 0);
}

function showPageLoader() {
	// SHOW overlay
	$('#overlay').show();
	$('#overlay').fadeTo("def", .3);
	// Prevent default action of link:
	return false;
}

function hidePageLoader() {
	// HIDE overlay
	$('#overlay').hide();
	$('#overlay').fadeTo("def", 0);
	// Prevent default action of link:
	return false;
}


function showLoader(tag, fromTop) {

	html = "<div align='center'><div style='height:"+fromTop+"px'></div><img src='content/loader.gif'/></div>";
	$(tag).html(html);

}
function hideLoader(tag) {
	html = "";
	$(tag).html(html);
}

function checkEnter(e, func){ //e is event object passed from function invocation

	var characterCode; //literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit() //submit the form
		func();
		return false;
	} else {
		return true;
	}
}

function openPopup(url, width, height){
	var options="menubar=no,width="+width+",height="+height+",toolbar=no"
	window.open(url,"Window1",
	options);
}


