﻿

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupUserStory").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupUserStory").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup HDTT
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupUserStory").height();
	var popupWidth = $("#popupUserStory").width();
	//centering

    $('#popupUserStory').center();
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
//	$.ajax({
//	type: "POST",
//	    url: "Service.asmx/GetUserStory",
//	    data: "{'HDTT':'" + HDTT + "'}",
//	    contentType: "application/json; charset=utf-8",
//	    dataType: "json",
//	    success: function(response) {
//	        $("#UserStoryContentArea").html(response.d);
//	    }
//	});

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    //LOADING POPUP
    //Click the button event!
    $(".ShowGallery").click(function() {
        //centering with css $(this).attr('HDTT')
        centerPopup();
        //load popup
        loadPopup();
        var d = new Date();
        var myDate = new Date();
        var mytime = '' + myDate.getTime()
        $('#LoadPage').load('/BilledGalleri.aspx?GID=' + $(this).attr("GID") + '&t=' + mytime);
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupUserStoryClose").click(function() {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});


(function($) {
    $.fn.extend({
        center: function(options) {
            var options = $.extend({ // Default values 
                inside: window, // element, center into window 
                transition: 0, // millisecond, transition time 
                minX: 0, // pixel, minimum left element value 
                minY: 0, // pixel, minimum top element value 
                withScrolling: true, // booleen, take care of the scrollbar (scrollTop) 
                vertical: true, // booleen, center vertical 
                horizontal: true // booleen, center horizontal 
            }, options);
            return this.each(function() {
                var props = { position: 'absolute' };
                if (options.vertical) {
                    var top = ($(options.inside).height() - $(this).outerHeight()) / 2;
                    if (options.withScrolling) top += $(options.inside).scrollTop() || 0;
                    top = (top > options.minY ? top : options.minY);
                    $.extend(props, { top: top + 'px' });
                }
                if (options.horizontal) {
                    var left = ($(options.inside).width() - $(this).outerWidth()) / 2;
                    if (options.withScrolling) left += $(options.inside).scrollLeft() || 0;
                    left = (left > options.minX ? left : options.minX);
                    $.extend(props, { left: left + 'px' });
                }
                if (options.transition > 0) $(this).animate(props, options.transition);
                else $(this).css(props);
                return $(this);
            });
        }
    });
})(jQuery); 
