﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusAsc = 0;
var popupStatusFriend = 0;
var popupStatusOrder = 0;
//loading popup with jQuery magic!
function loadPopupAsc(a ){
	//loads popup only if it is disabled
	if(popupStatusAsc==0){
	
		if (a ) {
		jQuery("#product_id").val(a);
		//jQuery("#popupFriendContact").find('input[name="price"]').val(current_price+"лв.");

		}
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popupContact").fadeIn("slow");
		popupStatusAsc = 1;
	}
}
function loadPopupOrder(a ){
	//loads popup only if it is disabled
	if(popupStatusOrder==0){
	
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popupOrder").fadeIn("slow");
		popupStatusOrder = 1;
	}
}

function loadPopupFriend(){
	//loads popup only if it is disabled
	
	if(popupStatusFriend==0){
		jQuery("#backgroundFriendPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundFriendPopup").fadeIn("slow");
		jQuery("#popupFriendContact").fadeIn("slow");
		//
		popupStatusFriend = 1;
	}
}
function disablePopupOrder(){
	//disables popup only if it is enabled
	if(popupStatusOrder==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popupOrder").fadeOut("slow");
		popupStatusOrder = 0;
	}
}
//disabling popup with jQuery magic!
function disablePopupAsc(){
	//disables popup only if it is enabled
	if(popupStatusAsc==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popupContact").fadeOut("slow");
		popupStatusAsc = 0;
	}
}
function disablePopupFriend(){
	//disables popup only if it is enabled
	if(popupStatusFriend==1){
		jQuery("#backgroundFriendPopup").fadeOut("slow");
		jQuery("#popupFriendContact").fadeOut("slow");
		popupStatusFriend = 0;
	}
}
//centering popup
function centerPopupAsc(a){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupContact").height();
	var popupWidth = jQuery("#popupContact").width();
	//centering
	var top;
	if (a) {
		top = windowHeight/2-popupHeight/2-1200;
	}else {
		top = windowHeight/2-popupHeight/2;
	}
	jQuery("#popupContact").css({
		"position": "absolute",
        "top": ((windowHeight - jQuery("#popupContact").outerHeight()) / 2) + jQuery(window).scrollTop() + "px",
        "margin-left": "auto",
        "margin-right": "auto"
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function centerPopupOrder(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupOrder").height();
	var popupWidth = jQuery("#popupOrder").width();
	//centering
	jQuery("#popupOrder").css({
		"position": "absolute",
        "top": ((windowHeight - jQuery("#popupOrder").outerHeight()) / 2) + jQuery(window).scrollTop() + "px",
        "margin-left": "auto",
        "margin-right": "auto"
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function centerPopupFriend(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupFriendContact").height();
	var popupWidth = jQuery("#popupFriendContact").width();
	//centering
	jQuery("#popupFriendContact").css({
		"position": "absolute",
        "top": ((windowHeight - jQuery("#popupFriendContact").outerHeight()) / 2) + jQuery(window).scrollTop() + "px",
        "margin-left": "auto",
        "margin-right": "auto"
	});
	//only need force for IE6
	
	jQuery("#backgroundFriendPopup").css({
		"height": windowHeight
	});
	
}


jQuery.noConflict();
jQuery(document).ready(function(jQuery){
	
	//LOADING POPUP
	//Click the button event!
	jQuery('div[id*="send_mail_"]').click(function(){
		
		centerPopupFriend();
		//load popup
		loadPopupFriend();
		
		jQuery("#popupFriendContact").find('input[name="product"]').val(current_name);
		jQuery("#popupFriendContact").find('input[name="price"]').val(current_price+"лв.");
		
	});
jQuery("#send_to_friend_product").click(function(){
		
		centerPopupFriend();
		
		loadPopupFriend();
	});
jQuery("#asc_for_product_id").click(function(a){
		
		centerPopupAsc();
		//load popup
		loadPopupAsc(a);
});
jQuery("#ask_btn").click(function(){
		centerPopupAsc();
		//load popup
		loadPopupAsc();
});		
jQuery("#order_btn").click(function(){
		centerPopupOrder();loadPopupOrder();
});		

	//CLOSING POPUP
	//Click the x event!
	jQuery("#popupContactClose").click(function(){
		disablePopupAsc();
	});
	jQuery("#popupOrderClose").click(function(){
		disablePopupOrder();
	});	
	jQuery("#popupFriendContactClose").click(function(){
		disablePopupFriend();
	});
	//Click out event!
	jQuery("#backgroundPopup").click(function(){
		disablePopupAsc();
	});
	jQuery("#backgroundPopup").click(function(){
		disablePopupOrder();
	});	
	jQuery("#backgroundFriendPopup").click(function(){
		disablePopupFriend();
	});
	
	//
	
	jQuery('#send_friend_mail_btn').live('click',function(){
		
	});
	//Press Escape event!
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && (popupStatusAsc==1 || popupStatusOrder == 1)){
			disablePopupAsc();
			disablePopupFriend();
			disablePopupOrder();
		}
		
	});

});
