﻿/***************************/
//@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 popupStatus = 0;
var probeer = 0;
function update(){
		$.get('zien.php', function(data) {
								 //  alert(data);
					if(data == 'U heeft nog geen producten in uw winkelwagen!'){
						$('.title').text(data);
						$('.ajabas').html('');
					}
					else
					{
						$('.ajabas').html(data);
						$('.title').text('');
					}
				});
	}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$('.basket').live('click', function(e) {
		//centering with css
		
		probeer = $(this).attr("id");
		centerPopup();
		//load popup
		loadPopup(probeer);
		e.preventDefault();
	});
	
	$('#tdw').click(function(){
		$artikel = probeer.split('_');
		
		$.post("add.php", { id: $artikel[1], aantal: $('#aantal').val() },
			   function(data) {
				// alert("Data Loaded: " + data);
					update();
			   });
		update();
		disablePopup();
		//alert('clcik');
	});
	$('#tww').click(function(e){
							 e.preventDefault();
		$artikel = probeer.split('_');
		
		$.post("add.php", { id: $artikel[1], aantal: $('#aantal').val() },
			   function(data) {
				// alert("Data Loaded: " + data);
					update();
					$(window.location).attr('href', 'http://www.worldofgifts.eu/winkelmand/');
					//alert('done');
			   });
		update();
	//	
		disablePopup();
		
		//alert('clcik');
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$artikel = probeer.split('_');
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		$('#aantal').val(1);
		//alert('artikel-enkel-js.php?id='+$artikel[1]);
		$.get('artikel-enkel-js.php?do=img&id='+$artikel[1], function(data) {
								 //  alert(data);
			$('.popupleft').html(data);
		});
		$.get('artikel-enkel-js.php?do=artinfo&id='+$artikel[1], function(data) {
								 //  alert(data);
			$('.oms').html(data);
		});
		
		popupStatus = 1;
	}
}
