
//PORTFOLIO POPUP (BEGIN)=======================================================
var popupStatus = 0;
var popup="";
//loading popup with jQuery magic!
function loadPopup(popup){
	//alert(popup);
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(".backgroundPopup").css({
			"opacity": "0.9"
		});
		$(".backgroundPopup").fadeIn("slow");
		$(popup).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(popup){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(".backgroundPopup").fadeOut("slow");
		$(popup).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(popup){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;	
	var popupHeight = $(popup).height();
	var popupWidth = $(popup).width();
	//centering
	$(popup).css({
		"position": "absolute",
		"top":50,// windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	//alert(windowWidth);
	$(".backgroundPopup").css({
		"height": window.innerHeight,
		"width": windowWidth-2
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".click").click(function(){
		//centering with css
		popup="#"+this.getAttribute('alt');
		//alert(popup);
		//alert(document.getElementById(this.getAttribute('alt')).innerHTML);
		centerPopup(popup);
		//load popup
		loadPopup(popup);
	});
	
	//CLOSING POPUP
	//Click the x event!
	$(".popupCertificatesClose").click(function(){
		disablePopup(popup);
	});
	$(".popupSendEmailClose").click(function(){
		disablePopup(popup);
	});
	//Click out event!
	$(".backgroundPopup").click(function(){
		disablePopup(popup);
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
//PORTFOLIO POPUP (END)=======================================================

//PORTFOLIO LIST CLICK (BEGIN)================================================
$(document).ready(function() 
{
	$('ul.filter a').click(function() 
	{
		var i = 0;							
		$(this).css('outline','none');
		$('ul.filter .current').removeClass('current');
		$(this).parent().addClass('current');		
		var filterVal = $(this).text().toLowerCase();
		filterVal = removeSpaces(filterVal);
		//alert (filterVal);
		if(filterVal == 'all') {
			document.getElementById('portfoliuTitle').innerHTML="&nbsp;" + $(this).text();
			$('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
		} 
		else 
		{			
			$('ul#portfolio li').each(function() 
				{
				if(!$(this).hasClass(filterVal)) 
				{
					$(this).fadeOut('slow').addClass('hidden');
				} 
				else 
				{
					i=i +1;
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
			document.getElementById('portfoliuTitle').innerHTML="&nbsp;Filter&nbsp;by:&nbsp;" + $(this).text()+"&nbsp;-&nbsp;["+i+"&nbsp;items]";
		}
		
		return false;
	});
});
function removeSpaces(string) 
{
	var name = string.split(' ').join('-');
  	name = name.split(',').join('');
	name = name.split('+').join('');
	name = name.split('/').join('');
	name = name.split('.').join('');
	
	return name
}
//PORTFOLIO LIST CLICK (END)================================================

//PORTFOLIO comments show (begin)============================================
$(document).ready(function(){

	$(".click a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-125"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-175"}, "fast");
	});


});
//PORTFOLIO comments show (end)============================================
