$(document).ready(function() {
$('#mango-content').click(function() {
	return false;
})
$('#mango-body').click(function() {
	closeForm();
})
$(document).keyup(function(e) { 
    if (e.which == 27) { closeForm();}  // esc   (does not work)
});
})

function reloadPage(){
location.reload(true)

}
function closeForm(){
		$("#mango-body").fadeOut('fast',function(){$(this).remove()});
		return false;

}
 function showPopUp(url) {
	 
	//var url= $(obj).attr("href");
	var arrPageSizes = ___getPageSize();
	var arrPageScroll = ___getPageScroll();
	//history.pushState(stateObj, "curentpage", task);
	//url= ser'+task;
	_loading();
	$.get(url,function(data){
		$('#mango-content').html(data);
		$('#mango-content').append('<a href="javascript:void(0)" onclick="return closeForm()" class="mango-close">Close</a>');
		$("#shapeblue").remove();
		$("#shapepink").remove();
		var hpop =  $("#mango-content").height();
		var availHeight=window.innerHeight;
		$('#mango-content').css({
					top:	(availHeight-hpop)/2,
			
		}).fadeIn(200);
	});
		return false;
	};

   function playAnimation(){
	   
            var movex = $("#shapeblue").width() + 4;
			
			moveleft("#shapeblue",movex);
			moveright("#shapeblue",movex);
			moveright("#shapepink",movex);
			moveleft("#shapepink",movex);


        }

            function moveleft(el,movex) {
                $(el).animate({
                    left: '+='+movex
                }, 800, function() {
                    $(el).css("z-index", "9000");
                });
            }

            function moveright(el,movex) {
               $(el).animate({
                    left: '-='+movex
                }, 800, function() {
                    $(el).css("z-index", "9001");
                });
            }
	
function _loading(){
	var arrPageSizes = ___getPageSize();
	var arrPageScroll = ___getPageScroll();
	$("#mango-body").remove();
	$('body').append('<div id="mango-body"><div id="mango-content"></div></div>');
	$('#mango-body').append('<div id="shapeblue" class="bar"></div><div id="shapepink" class="bar"></div>');
			$("#shapeblue").show();
			$("#shapepink").show();
			setInterval(playAnimation, 100);
			var wwidth = $(window).width();
			var wheight = $(window).height();
			//alert(wheight);
			var bluewidth = $("#shapeblue").width();
			$("#shapeblue").css("left", (wwidth/2) - bluewidth);
			$("#shapeblue").css("top", (wheight/2) - bluewidth);
			var bluepos = $("#shapeblue").position();
			var movex = $("#shapeblue").width() + 4;
			$("#shapepink").css("left", (wwidth/2) - bluewidth);
			$("#shapepink").css("top", (wheight/2) - bluewidth);
			
		//alert(arrPageScroll);	
	$('#mango-body').css({
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
	});

}

function explode (delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
    var emptyArray = {
        0: ''
    };

    // third argument is not required
    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {
        return null;
    }

    if (delimiter === '' || delimiter === false || delimiter === null) {
        return false;
    }

    if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
        return emptyArray;
    }

    if (delimiter === true) {
        delimiter = '1';
    }

    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};


