var loading = {

    isVisible : false,

    draw : function()
    {
        var $el = $('<div></div>');
        $el.css({
            width: '40px',
            height: '40px',
            background: 'url()'
        });
        $('body').append();
    }

}

var zGal = {
	
	baseUrl : '',
	
	isLoading : false,
	isFirstFullscreenView		: true,
	
	gallery						: new Array(),
	currentGalleryIsOpen		: false,
	currentGalleryIsThumbOpen	: false,
	
	currentGalleryCenterPage	: 1,
	currentGalleryCenterPerPage	: 0,
	currentGalleryCenterPages	: 0,
	
	currentGalleryRightPage		: 1,
	currentGalleryRightPerPage	: 0,
	currentGalleryRightPages	: 0,
	
	currentGalleryIndex 		: 0,
	currentGalleryTotal			: 0,
	currentGalleryInterval		: null,
	currentGalleryName			: '',
	currentGalerySelectedImage	: '',
	currentGalleryStop			: false,
	currentGalleryTmpInterval 	: 0,
	isRightMenuOpen					:function(){
		if ($('#right-menu-opened').css('right').replace('px','')==0){
					return true;
					}else{
						return false;
						}
		
		},
	isLeftMenuOpen			:function(){
		if ($('#left-menu-opened').css('left').replace('px','')==0){
					return true;
					}else{
						return false;
						}
		
		},
	wasRightMenuOpened			:false,
	wasLeftMenuOpened			:true,
	dY : 0,
	dX : 0,
	
	openAfterLoading : function(callback){
		this.callback=callback;
		if($('#loading-img').is(':hidden')){
			
			typeof(callback) == 'function' ? callback.call() : '';
			//animate.hideMinimumMenuRight(function(){animate.showMenuRight()});
			
			}	else{
				//alert('disparou');
				setTimeout("zGal.openAfterLoading(this.callback)",800);
				
				}
		
		},
		
		openRightMenu : function(){
			animate.hideMinimumMenuRight(function(){animate.showMenuRight()});
			
			},
			closeRightMenu : function(){
			
			animate.hideMenuRight(function(){animate.showMinimumMenuRight()});
			},
			openLeftMenu : function(){
			animate.hideMinimumMenu(function(){animate.showMenu()});
			
			},
			closeLeftMenu : function(){
			
			animate.hideMenu(function(){animate.showMinimumMenu()});
			},
			
			
			
	loadGallery : function(galleryId, pLnk)
	{
		var opened;
		if($(pLnk).attr('class')!=undefined){
			opened=$(pLnk).attr('class').indexOf("opened");		
		}else{
			opened=-1;
			}
		if (opened!=-1){
			return false;
		}else{
			$('#toolbox li.play a').removeClass('opened dr');
			$('body').unbind('mousemove');
		
			if (is.busy())
			{
				
				$('#holder div img').fadeOut('slow', function(){
					$(this).remove();
				
				
				
				
				zGal.currentImgWidth = 50;
				zGal.currentImgHeight = 50;
				zGal.resizeImage();
				});
				$('#holder div').append($('<img src="' + zGal.baseUrl + 'img/gallery-thumbs.jpg" />').addClass('current'));
				animate.galleryHide();
				animate.hideToolBox();
				animate.hideMenuRight();
				animate.hideMinimumMenuRight();
				
				zGal.isLoading = true;
				is.varBusy = true;
				
				zGal.stopGallery();
				zGal.showLoadingImg();
				
				content.hide();
				
				// allready loaded
				if (typeof(zGal.gallery[galleryId]) !== 'undefined' && galleryId !== 'lightbox')
				{
					
					zGal.resetGallery();
					zGal.currentGalleryName 	= galleryId;
					zGal.currentGalleryTotal 	= zGal.gallery[galleryId].length;
					zGal.prepareCategoryCenter();
					
				}else{
					$.getJSON('home/gallery/' + galleryId, function(data){
						if(data.gallery!=='undefined'){
						if (data.sucess)
						{
							zGal.resetGallery();
							zGal.setGalleryName(galleryId);
							
							$.each(data.gallery, function(key, obj){
								zGal.addGalleryImage(
									obj.imgId,
									obj.imgNormalFile,
									obj.imgThumbFile,
									obj.imgWidth,
									obj.imgHeight,
									obj.imgDirector,
									obj.imgClient,
									obj.imgAgency
								);
							});
							
							setTimeout(function(){
								zGal.currentGalleryTotal = zGal.gallery[galleryId].length;
								zGal.prepareCategoryCenter();
							}, 1200);
							
						}else{
							
							if(galleryId==='lightbox'){
							animate.setMessage('The lightbox is empty!');

							}
							zGal.stopShowLoadingImg();
							zGal.isLoading = false;
							is.varBusy = false;
							
							var prepared = $('#gallery-middle div ul li').length;
							if (prepared)
							{
								for (var i = 0; i <= prepared; i++)
								{
									$('#gallery-middle div ul li').eq(i).hide(function(){
										$(this).remove();
									});
								}
	
							}
							
						}
						}else {
							
							if(galleryId==='lightbox'){
							animate.setMessage('The lightbox is empty!');

							}
							zGal.stopShowLoadingImg();
							zGal.isLoading = false;
							is.varBusy = false;
							
							var prepared = $('#gallery-middle div ul li').length;
							if (prepared)
							{
								for (var i = 0; i <= prepared; i++)
								{
									$('#gallery-middle div ul li').eq(i).hide(function(){
										$(this).remove();
									});
								}
	
							}
														
							}
							
					});
					
				}
				if ($('#right-menu-opened').css('right').replace('px','')==0){
					zGal.wasRightMenuOpened=true;
					}else{
						zGal.wasRightMenuOpened=false;
						}
				
			}
			
		}
	},
	
	

	adjustCategoryCenter : function()
	{
		if (zGal.currentGalleryIsOpen)
		{
			$('#gallery-holder').hide(0, function(){
				zGal.prepareCategoryCenter();
			});
		}
	},
	
	adjustCategoryRight : function()
	{
		if (zGal.currentGalleryIsThumbOpen)
		{
			zGal.prepareCategoryRight();
			if (zGal.currentGalerySelectedImage!=''){
			$(".thumbs ul li").each(function(){
						if($(this).find("img").attr("src")==zGal.currentGalerySelectedImage){
													//alert("selecionado;" + $(this).position().top + " lista:" + $(this).parents("ul").position().top);
													var dif =$(this).parents("ul").position().top - $(this).position().top;
													//alert(dif);
													$(this).parents("ul").animate({marginTop:'+=' + dif});
													$(this).attr("class","selecionado");
													$(this).parents("ul").attr("class","selParent")
						}
						})
			}
		}
	},
	
	/* ----------------------------------------------------------- */
	
	isAnimatingRightUp : false,
	categoryRightUp : function()
	{
		if(zGal.canRightUp() && !zGal.isAnimatingRightUp)
		{
			zGal.isAnimatingRightUp = true;
			var mt = (zGal.currentGalleryRightPerPage * 106);
			zGal.currentGalleryRightPage--;
			$('#right-menu-opened ul').animate({marginTop: parseInt($('#right-menu-opened ul').css('marginTop').replace('px', '')) + mt}, function(){
				zGal.isAnimatingRightUp = false;
			});
			zGal.canRightUp();
		}
		zGal.canRightDown();
	},
	
	canRightUp: function()
	{
		if (zGal.currentGalleryRightPage > 1)
		{
			$('#right-menu-opened .up').addClass('pointer').removeClass('no');
			return true;
		}else{
			$('#right-menu-opened .up').removeClass('pointer').addClass('no');
			return false;
		}
	},
	
	/* ----------------------------------------------------------- */
	
	isAnimatingRightDown : false,
	categoryRightDown: function()
	{
		if(zGal.canRightDown() && !zGal.isAnimatingRightDown)
		{
			zGal.isAnimatingRightDown = true;
			var mt = (zGal.currentGalleryRightPage * (zGal.currentGalleryRightPerPage * 106) * (-1));
			zGal.currentGalleryRightPage++;
			$('#right-menu-opened ul').animate({marginTop: mt}, function(){
				zGal.isAnimatingRightDown = false;
			});
			zGal.canRightDown();
		}
		zGal.canRightUp();
	},
	
	canRightDown: function()
	{
		if (zGal.currentGalleryRightPage < zGal.currentGalleryRightPages)
		{
			$('#right-menu-opened .down').addClass('pointer').removeClass('no');
			return true;
		}else{
			$('#right-menu-opened .down').removeClass('pointer').addClass('no');
			return false;
		}
	},
	
	/* ----------------------------------------------------------- */
	
	isAnimatingCenterUp : false,
	categoryCenterUp : function()
	{
		if(zGal.canCenterUp() && !zGal.isAnimatingCenterUp)
		{
			zGal.isAnimatingCenterUp = true;
			var mt = (zGal.currentGalleryCenterPerPage * 207);
			zGal.currentGalleryCenterPage--;
			$('#gallery-middle ul').animate({marginTop: parseInt($('#gallery-middle ul').css('marginTop').replace('px', '')) + mt}, function(){
				zGal.isAnimatingCenterUp = false;
			});
			zGal.canCenterUp();
		}
		zGal.canCenterDown();
	},
	
	canCenterUp: function()
	{
		if (zGal.currentGalleryCenterPage > 1)
		{
			$('#gallery-top div').addClass('pointer').removeClass('no');
			return true;
		}else{
			$('#gallery-top div').removeClass('pointer').addClass('no');
			return false;
		}
	},
	
	/* ----------------------------------------------------------- */
	
	isAnimatingCenterDown : false,
	categoryCenterDown: function()
	{
		if(zGal.canCenterDown() && !zGal.isAnimatingCenterDown)
		{
			zGal.isAnimatingCenterDown = true;
			var mt = (zGal.currentGalleryCenterPage * (zGal.currentGalleryCenterPerPage * 207) * (-1));
			zGal.currentGalleryCenterPage++;
			$('#gallery-middle ul').animate({marginTop: mt}, function(){
				zGal.isAnimatingCenterDown = false;
			});
			zGal.canCenterDown();
		}
		zGal.canCenterUp();
	},
	
	canCenterDown: function()
	{
		if (zGal.currentGalleryCenterPage < zGal.currentGalleryCenterPages)
		{
			$('#gallery-bottom div').addClass('pointer').removeClass('no');
			return true;
		}else{
			$('#gallery-bottom div').removeClass('pointer').addClass('no');
			return false;
		}
	},
	
	/* ----------------------------------------------------------- */
	
	prepareCategoryRight : function()
	{
		
		zGal.currentGalleryIsThumbOpen 	= true;
		
		$('#right-menu-opened ul').animate({marginTop:0});
		
		
		$('#right-menu-opened ul li').remove();
		/*
		var prepared = $('#right-menu-opened ul li').length;
		if (prepared)
		{
			for (var i = 0; i <= prepared; i++)
			{
				$('#right-menu-opened ul li').eq(i).hide(function(){
					$(this).remove();
				});
			}
		}
		*/

		var perPage = Math.floor(($(window).height() - 290) / 106);
		
		zGal.currentGalleryRightPage 	= 1;
		zGal.currentGalleryRightPerPage = perPage;
		zGal.currentGalleryRightPages 	= Math.ceil(zGal.gallery[zGal.currentGalleryName].length / perPage);
		
		zGal.canRightDown();
		zGal.canRightUp();

		$('#right-menu-opened div.thumbs').height(((perPage * 106) - 10));
		
		elPos.rightMenu();
		
		var i = 0;
		
		$.each(zGal.gallery[zGal.currentGalleryName], function(key, obj){
			//alert(obj.imgThumbFile.src)
			li = $('<li><p></p></li>');
			
			$(obj.imgThumbFile).clone().css({height:90,width:90}).appendTo(li.find('p'));
			
			$('#right-menu-opened ul').append(li);
			
			li.fadeIn('slow');
			
			i++;
			
			if (i == zGal.currentGalleryTotal)
			{
				
				$('#right-menu-opened li').each(function(){
					
					$(this).bind('mouseenter', function(){
						$(this).css({border:'3px solid #f50'});
					});
					
					$(this).bind('mouseleave', function(){
						$(this).css({border:'3px solid #808080'});
					});
					
					$(this).bind('click',  function(){
                        content.hide();
						
						$('#toolbox li.play a').removeClass('opened dr');
						var index = $('#right-menu-opened li').index($(this));
						
						zGal.stopGallery();
						zGal.showLoadingImg();
						
						zGal.currentGalleryIndex 	= index + 1;
						zGal.currentImgWidth  		= zGal.gallery[zGal.currentGalleryName][index][0];
						zGal.currentImgHeight 		= zGal.gallery[zGal.currentGalleryName][index][1];
						zGal.showImage(zGal.gallery[zGal.currentGalleryName][index]['imgNormal'], zGal.currentGalleryName, setTimeout("zGal.firstZoom()", 2000));
						
						$(".thumbs ul li.selecionado").attr('class','')
						zGal.currentGalerySelectedImage=$(this).find("img").attr("src");						
						$(this).attr("class","selecionado");
						$(this).parents("ul").attr("class","selParent")
						//alert("selecionado;" + $(this).position().top + " lista:" + $(this).parents("ul").position().top);
						var dif =$(this).parents("ul").position().top - $(this).position().top;
						//alert(dif);
													$(this).parents("ul").animate({marginTop:'+=' + dif});
						zGal.currentGalleryIsOpen = false;
						
						animate.showToolBox();
						
	
	animate.galleryHide();
					

					}						
								
						);
						
	
	});
				
					
				
			}
	
			});

	},
	firstZoom:function(callBack){
		//if(toolBox.isVisible){
			if(zGal.isFirstFullscreenView){
			typeof(callBack) == 'function' ? animate.setMessage("Click to zoom in and click again to zoom out",'',callBack) : animate.setMessage("Click to zoom in and click again to zoom out");
				zGal.isFirstFullscreenView=false
				}else{
					typeof(callBack) == 'function' ? callBack.call() : '';
					}
			
		//}
		
		},
	prepareCategoryCenter : function(callback)
	{
		
		zGal.currentGalleryIsThumbOpen = false;
		
		zGal.prepareCategoryRight();
		
		animate.galleryShow();
		
		zGal.currentGalleryIsOpen = true;
		
		$('#gallery-middle ul').animate({marginTop:0});
		
		zGal.currentGalleryCenterLine = 1;
		
		is.varBusy = true;
		
		$('#holder div img').fadeOut('slow', function(){
			$(this).remove();
		});
		
		$('#holder div').append($('<img src="' + zGal.baseUrl + 'img/gallery-thumbs.jpg" />').addClass('current'));
		zGal.currentImgWidth = 50;
		zGal.currentImgHeight = 50;
		zGal.resizeImage();
		
		$('#gallery-middle div ul li').remove();
		/*
		var prepared = $('#gallery-middle div ul li').length;
		if (prepared)
		{
			for (var i = 0; i <= prepared; i++)
			{
				$('#gallery-middle div ul li').eq(i).hide(function(){
					$(this).remove();
				});
			}
		}
		*/
		
		var perLine = Math.floor(($(window).width() - 470) / 207);
		//perLine = perLine > 5 ? 5 : perLine;
		
		var h = Math.floor(($(window).height() - 210) / 207);
		
		zGal.currentGalleryCenterPage 		= 1;
		zGal.currentGalleryCenterPerPage 	= h;
		zGal.currentGalleryCenterPages 		= Math.ceil(zGal.gallery[zGal.currentGalleryName].length / (h * perLine));
		
		zGal.canCenterDown();
		zGal.canCenterUp();
		
		var w = (perLine * 207) - 10;
		
		perLine = perLine - 1;
		
		h = (h * 207) - 10;

		$('#gallery-middle, #gallery-middle > div').width(w+50).height(h+10);
		
		$('#gallery-holder').width(w).height(h + 100);
		
		elPos.galleryThumbsCenter();
		
		var selectedIndex = selectedIndex | null; 
		
		var c = 0, l = 0, i = 0, li;
		
		$.each(zGal.gallery[zGal.currentGalleryName], function(key, obj){
			
			li = $('<li><p></p></li>');
			li.find('p').append(obj.imgThumbFile);
			
			//c == 0 ? li.css({marginLeft:0}) : '';
			//l == 0 ? li.css({marginTop:0}) : '';
			
//			if (c == perLine)
//			{
//				li.css({marginRight:0});
//				c = -1;
//				l++;
//			}
			
			$('#gallery-middle div ul').append(li);
			
			li.fadeIn('slow');
			
			c++;
			i++;
			
			if (i == zGal.currentGalleryTotal)
			{
				zGal.stopShowLoadingImg();
				zGal.isLoading = false;
				is.varBusy = false;
				
				$('#gallery-middle li').each(function(){

					$(this).bind('mouseenter', function(){
						$(this).css({border:'3px solid #f50'});
					});
					
					$(this).bind('mouseleave', function(){
						$(this).css({border:'3px solid #808080'});
					});
					
					$(this).bind('click', function(){
												  
				
						var index = $('#gallery-middle li').index($(this));
						
						zGal.stopGallery();
				
						 zGal.showLoadingImg();
						zGal.currentGalleryIndex 	= index + 1;
						zGal.currentImgWidth  		= zGal.gallery[zGal.currentGalleryName][index][0];
						zGal.currentImgHeight 		= zGal.gallery[zGal.currentGalleryName][index][1];
						zGal.showImage(zGal.gallery[zGal.currentGalleryName][index]['imgNormal'], zGal.currentGalleryName, setTimeout("zGal.firstZoom()", 2000));
						zGal.currentGalerySelectedImage=$(this).find("img").attr("src");
						zGal.currentGalleryIsOpen = false;
						$(".thumbs ul li").each(function(){
						if($(this).find("img").attr("src")==zGal.currentGalerySelectedImage){
													$(this).attr("class","selecionado");
													$(this).parents("ul").attr("class","selParent")
													var dif =$(this).parents("ul").position().top - $(this).position().top;
													//alert(dif);
													$(this).parents("ul").animate({marginTop:'+=' + dif});
													//alert("selecionado;" + $(this).position().top + " lista:" + $(this).parents("ul").position().top);
						}
						})
						animate.showToolBox();
				
						animate.galleryHide();
						//animate.hideMenuRight();
						//animate.showMinimumMenuRight();
						//if(toolBox.isVisible){
			/*if(zGal.isFirstFullscreenView){
				animate.setMessage("Click to zoom in and click again to zoom out");
			zGal.isFirstFullscreenView=false
			}*/
			//}
						
					}
							
			
			);
				
						
					
				});
				
				typeof(callback) == 'function' ? callback.call() : '';
				
				elPos.galleryThumbsCenter();
				
				
				if(zGal.wasRightMenuOpened){
					zGal.openAfterLoading(zGal.openRightMenu);					
					}else{
						zGal.openAfterLoading(zGal.closeRightMenu);
						}
								
				//animate.hideMenuRight();
				//animate.showMinimumMenuRight();
				
			}
			
		});
		
	},

    resize2 : function(callback)
	{

		zGal.currentGalleryIsThumbOpen = false;

		zGal.prepareCategoryRight();

		animate.galleryShow();

		zGal.currentGalleryIsOpen = true;

		$('#gallery-middle ul').animate({marginTop:0});

		zGal.currentGalleryCenterLine = 1;

		is.varBusy = true;

//		$('#holder div img').fadeOut('slow', function(){
//			$(this).remove();
//		});

		//$('#holder div').append($('<img src="' + zGal.baseUrl + 'img/gallery-thumbs.jpg" />').addClass('current'));
		zGal.currentImgWidth = 50;
		zGal.currentImgHeight = 50;
		zGal.resizeImage();

//		$('#gallery-middle div ul li').remove();
		/*
		var prepared = $('#gallery-middle div ul li').length;
		if (prepared)
		{
			for (var i = 0; i <= prepared; i++)
			{
				$('#gallery-middle div ul li').eq(i).hide(function(){
					$(this).remove();
				});
			}
		}
		*/

		var perLine = Math.floor(($(window).width() - 470) / 207);
		//perLine = perLine > 5 ? 5 : perLine;

		var h = Math.floor(($(window).height() - 210) / 207);

		zGal.currentGalleryCenterPage 		= 1;
		zGal.currentGalleryCenterPerPage 	= h;
		zGal.currentGalleryCenterPages 		= Math.ceil(zGal.gallery[zGal.currentGalleryName].length / (h * perLine));

		zGal.canCenterDown();
		zGal.canCenterUp();

		var w = (perLine * 207) - 10;

		perLine = perLine - 1;

		h = (h * 207) - 10;

		$('#gallery-middle, #gallery-middle > div').width(w+50).height(h+10);

		$('#gallery-holder').width(w).height(h + 100);

		elPos.galleryThumbsCenter();

		var selectedIndex = selectedIndex | null;

		var c = 0, l = 0, i = 0, li;

        zGal.stopShowLoadingImg();
        zGal.isLoading = false;
        is.varBusy = false;

//        $('#gallery-middle li').each(function(){
//
//					$(this).bind('mouseenter', function(){
//						$(this).css({border:'3px solid #f50'});
//					});
//
//					$(this).bind('mouseleave', function(){
//						$(this).css({border:'3px solid #808080'});
//					});
//
//					$(this).bind('click', function(){
//
//
//						var index = $('#gallery-middle li').index($(this));
//
//						zGal.stopGallery();
//
//						zGal.showLoadingImg();
//						zGal.currentGalleryIndex 	= index + 1;
//						zGal.currentImgWidth  		= zGal.gallery[zGal.currentGalleryName][index][0];
//						zGal.currentImgHeight 		= zGal.gallery[zGal.currentGalleryName][index][1];
//						zGal.showImage(zGal.gallery[zGal.currentGalleryName][index]['imgNormal'], zGal.currentGalleryName, setTimeout("zGal.firstZoom()", 2000));
//						zGal.currentGalerySelectedImage=$(this).find("img").attr("src");
//						zGal.currentGalleryIsOpen = false;
//						$(".thumbs ul li").each(function(){
//						if($(this).find("img").attr("src")==zGal.currentGalerySelectedImage){
//													$(this).attr("class","selecionado");
//													$(this).parents("ul").attr("class","selParent")
//						}
//						})
//						animate.showToolBox();
//
//						animate.galleryHide();
//						//animate.hideMenuRight();
//						//animate.showMinimumMenuRight();
//						//if(toolBox.isVisible){
//			/*if(zGal.isFirstFullscreenView){
//				animate.setMessage("Click to zoom in and click again to zoom out");
//			zGal.isFirstFullscreenView=false
//			}*/
//			//}
//
//					}
//
//
//			);
//
//
//
//				});

	},
	
	setGalleryName : function(galleryName)
	{
		zGal.currentGalleryName 	= galleryName;
		zGal.gallery[galleryName] 	= new Array();
	},
	
	addGalleryImage : function(imgId, imgNormalFile, imgThumbFile, imgWitdh, imgHeight, imgDirector, imgClient, imgAgency)
	{
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal] = new Array(6);
		
		
		/*
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal]['imgNormal'] = new Image();
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal]['imgNormal'].src = zGal.baseUrl + 'home/image/' + imgNormalFile;
		*/
		
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal]['imgNormal'] = zGal.baseUrl + 'uploads/image/' + imgNormalFile;
		
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal]['imgThumbFile'] = new Image();
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal]['imgThumbFile'].src = zGal.baseUrl + 'uploads/image/' + imgThumbFile;
		
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][0] = imgWitdh;
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][1] = imgHeight;
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][2] = imgDirector;
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][3] = imgClient;
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][4] = imgAgency;
		zGal.gallery[zGal.currentGalleryName][zGal.currentGalleryTotal][5] = imgId;
				
		zGal.currentGalleryTotal++;
	},
	
	galleryAutoPlay : function (galleryName, interval)
	{
		
		//zGal.showLoadingImg();

		zGal.currentGalleryTmpInterval = interval;
		
		zGal.currentGalleryIndex = (zGal.currentGalleryIndex + 1) > zGal.currentGalleryTotal ? 0 : zGal.currentGalleryIndex;
		zGal.currentGalleryIndex = zGal.currentGalleryIndex < 0 ? 0 : zGal.currentGalleryIndex;
		
		if(typeof(zGal.gallery[galleryName][zGal.currentGalleryIndex]['imgNormal']) == 'string')
		{
			var url = zGal.gallery[galleryName][zGal.currentGalleryIndex]['imgNormal'];
			zGal.gallery[galleryName][zGal.currentGalleryIndex]['imgNormal'] = new Image();
			zGal.gallery[galleryName][zGal.currentGalleryIndex]['imgNormal'].src = url;
		}
		
		var img = zGal.gallery[galleryName][zGal.currentGalleryIndex]['imgNormal'];
		
		zGal.currentImgWidth  = zGal.gallery[galleryName][zGal.currentGalleryIndex][0];
		zGal.currentImgHeight = zGal.gallery[galleryName][zGal.currentGalleryIndex][1];
		
		zGal.currentGalleryIndex++;
		
		if (zGal.currentGalleryIndex > zGal.currentGalleryTotal)
		{
			zGal.currentGalleryIndex = 0;
		}
				
		clearInterval(zGal.currentGalleryInterval);

		if(zGal.currentGalleryStop == false)
		{
			if (img.complete)   
			{
				zGal.showImage($(img), galleryName);
				zGal.currentGalleryInterval = setInterval(function(){
					zGal.galleryAutoPlay(galleryName, interval)
				}, interval);
			}else{        
				zGal.currentGalleryIndex = zGal.currentGalleryIndex == 0 ? zGal.currentGalleryTotal - 1 : (zGal.currentGalleryIndex--) - 1;
				zGal.currentGalleryInterval = setInterval(function(){
					zGal.galleryAutoPlay(galleryName, interval)
				}, 1);
			}
		}else{
			zGal.stopShowLoadingImg();
			$('#holder div img.current').fadeTo(1);
		}

                
	},

	showImage : function (imgObject, galleryName,callback)
	{			
				
		if(typeof(imgObject) == 'string')
		{
			var url = imgObject;
			imgObject = new Image();
			imgObject.src = url;
		}
		$('#toolbox li.like a').removeClass('opened dr');
		$('#toolbox li.lightbox a').removeClass('opened dr');
		
		$('#toolbox li.zoom-in').removeClass('opened zoomin').find('a').removeClass('opened');
		$('#toolbox li.zoom').find('a').removeClass('opened');
		$('#toolbox li.zoom-out').addClass('zoomout').find('a').removeClass('opened');
		
		$('body').unbind('mousemove');
		
		var index 		= (zGal.currentGalleryIndex - 1) < 0 ? 0 : zGal.currentGalleryIndex - 1;
		var agency  	= zGal.gallery[galleryName][index][4];
		var director  	= zGal.gallery[galleryName][index][2];
		var client  	= zGal.gallery[galleryName][index][3];
			
		$('#footer div.fl p').eq(2).hide(0, function(){
			$('#footer div.fl p').eq(1).hide(0, function(){
				$('#footer div.fl p').eq(0).hide(0);
			});
		});
	
		$('#holder div').append($(imgObject).addClass('current dn'));
	
		if($('#holder div img').get().length>1){
		zGal.resizeImage(false, $('#holder div img').eq(1));
	
		$('#holder div img').eq(0).fadeOut(1500, function(){
				$(this).remove();
				
		
			});
			
		}else{
			zGal.resizeImage(false, $('#holder div img').eq(0));
			}
			
			
			
		$(imgObject).fadeIn(1000, function(){
			
			
			
			$('#footer div.fl p').eq(0).find('span').html(agency);
			$('#footer div.fl p').eq(1).find('span').html(director);
			$('#footer div.fl p').eq(2).find('span').html(client);
			
			$('#footer div.fl p').eq(0).fadeIn(300, function(){
				$('#footer div.fl p').eq(1).fadeIn(300, function(){
					$('#footer div.fl p').eq(2).fadeIn(300,function(){
																	$()		
																	typeof(callback) == 'function' ? zGal.stopShowLoadingImg(callback) : zGal.stopShowLoadingImg();	
																	
																	});
				});
				
			});
				
		});
		
					
	},	
		
	remover:function(object,callback){
		$(object).remove();
		
		
		},
	stopGallery : function()
	{
		$('#footer > div.fl > p').hide();
		zGal.currentGalleryStop = true;
		clearInterval(zGal.currentGalleryInterval);
		zGal.currentGalleryInterval = null;
	},
	
	continueGallery : function()
	{
		$('#footer > div.fl > p').show();
		zGal.currentGalleryStop = false;
		zGal.currentGalleryIndex = zGal.currentGalleryIndex == 0 ? zGal.currentGalleryTotal - 1 : (zGal.currentGalleryIndex--) - 1;
		zGal.galleryAutoPlay(zGal.currentGalleryName, zGal.currentGalleryTmpInterval);
	},
	
	resetGallery : function()
	{
		
		zGal.currentGalleryCenterPage		= 1,
		zGal.currentGalleryCenterPerPage	= 0,
		zGal.currentGalleryCenterPages		= 0,
		
		zGal.currentGalleryRightPage 	= 1;
		zGal.currentGalleryRightPerPage = 0;
		zGal.currentGalleryRightPages 	= 0;
		
		zGal.currentGalleryIndex 		= 0;
		zGal.currentGalleryTotal		= 0;
		zGal.currentGalleryInterval		= null;
		zGal.currentGalleryName			= '';
		zGal.currentGalleryStop			= false;
		zGal.currentGalleryTmpInterval 	= null;
		
	},
	
	/**
	 * Resize the current image and remove his fullscreen opts
	 */
	currentImgHeight : 0,
	currentImgWidth  : 0,
	
	windowHeight : 0,
	windowWidth  : 0,
	
	resizeImage : function(fade, im)
	{
		zGal.dY = 0,
		zGal.dX = 0,
		
		zGal.windowHeight = $(window).height();
		zGal.windowWidth = $(window).width();
		if (im==""||im==undefined||im=='undefined'){
			var img = $('#holder div img.current');
			//var img = $('#holder div img.new');
		}else{
			
			var img = im;
			}
			
		if (img.length && zGal.currentImgHeight >= zGal.windowHeight && zGal.currentImgWidth >= zGal.windowWidth)
		{
		
			var nHeight = (zGal.currentImgHeight * zGal.windowWidth) / zGal.currentImgWidth;
			
			var fade = fade || true;
			
			/*
			 * remove fade on resize window
			 */
			if (!fade)
			{
				img.removeAttr('style').fadeIn(0);
			}
			
			if (nHeight < zGal.windowHeight)
			{
				nWidth = width = (zGal.currentImgWidth * zGal.windowHeight) / zGal.currentImgHeight;
				img.height(zGal.windowHeight).width(nWidth).css({top:0});
				img.css({left: ((img.width() - zGal.windowWidth)/2) * (-1)});
			}else{
				img.width(zGal.windowWidth).height(nHeight).css({top:((zGal.windowHeight-nHeight)/2), left:0});
			}
		}else if (img.length){
			
			if (!fade)
			{
				img.removeAttr('style').fadeIn(0);
			}
		
			img.css({left: ((zGal.windowWidth - zGal.currentImgWidth)/2)});
			img.css({top: ((zGal.windowHeight - zGal.currentImgHeight)/2)});
			
		}
	},
	
	/**
	 * Loading Image
	 */
	loadingImgPos : function()
	{
		$('#loading-img').css({marginTop: (($(window).height() - $('#loading-img').height()) / 2), marginLeft: (($(window).width() - $('#loading-img').width()) / 2)});
	},
	
	showLoadingImg : function()
	{
		//$.fx.off=true;
		zGal.loadingImgPos();
		$('#loading-img').show();
	},
	
	stopShowLoadingImg : function(callback)
	{
		$('#loading-img').hide(0,function(){
											   typeof(callback) == 'function' ? callback.call() : '';
											   });
	}
	/* Loading Image ------------------------------------ */

};

var email = {
	
	isSending : false,
		
	show : function()
	{
	
		newsletter.hide();
		comment.hide();
		content.hide();
	
		$('#email').hide().find('span').html('');
		$('#email input').val('');
		$('#email .message').html('');
		elPos.emailBox();
		$('#email').css({'visibility':'visible'});
		$('#email').show();
		$('input[name=name').focus();
		
	},
	
	hide : function(visibility)
	{
		if(visibility==true){
			$('#email').css({'visibility':'hidden'});
			}else{
		$('#email').hide();
			}
	},
	
	send : function()
	{
		
		if (email.isSending == false)
		{
			//$('#email .message').html('<p>Sending...</p>');
			email.hide(true);
			animate.setMessage('Sending Image...');
			email.isSending = true;
			
			var index 	= zGal.currentGalleryIndex == 0 ? zGal.currentGalleryIndex : zGal.currentGalleryIndex - 1;
			var id 		= zGal.gallery[zGal.currentGalleryName][index][5];
			
			zGal.stopGallery();
			
			$.post('home/email/' + id + '/&' + $('#email form').serialize(), function(data){
				
				$('#email').find('span').html('');
				$('#email .message').html('');
				email.isSending = false;
				
				if (data.sucess)
				{
					//$('#email .message').html('<p>Your email was sent!</p>');
					//$('#email').find('span').html('');
					email.hide();
					animate.setMessage('Image sent!');
					
				}else{
					//animate.setMessage('THERE\'S SOME ERRORS ON YOUR FORM');
					//email.hide();
					animate.setMessage('Error!','',setTimeout('email.show()',1500));
					/*
					$('#email .message').html('<p>There\'s some erros on your form</p>');

					for(var i in data.fields)
					{
						$('#email').find('.error-' + i).html(data.fields[i]);
					}
					*/
				}
				
			});
			
		}
		
	}
		
}

var newsletter = {
		
	isSending : false,
		
	show : function()
	{
	
		email.hide();
		comment.hide();
		content.hide();
		
		$('#newsletter').hide().find('span').html('');
		$('#newsletter input').val('');
		$('#newsletter .message').html('');
		elPos.newsletterBox();
		$('#newsletter').css({'visibility':'visible'});
		$('#newsletter').show();
		$('input[name=name').focus();
		
	},
	
	hide : function(visibility)
	{
		if(visibility==true){
			$('#newsletter').css({'visibility':'hidden'});
			}else{
				$('#newsletter').hide();
				}
		
	},
	
	send : function()
	{
		
		if (newsletter.isSending == false)
		{
			
			//$('#newsletter .message').html('<p>Sending...</p>');
			newsletter.hide(true);
			animate.setMessage('Subscribing...');
			newsletter.isSending = true;
		
			$.post('home/newsletter/&' + $('#newsletter form').serialize(), function(data){
				
				$('#newsletter').find('span').html('');
				$('#newsletter .message').html('');
				newsletter.isSending = false;
				
				if (data.sucess)
				{
					/*
					$('#newsletter .message').html('<p>Your email was sent!</p>');
					$('#newsletter').find('span').html('');
					*/
					newsletter.hide();
					animate.setMessage('Subscribed! Thanks!');
					
				}else{
					//newsletter.hide();
					//alert(data)
					animate.setMessage('Error!','', setTimeout('newsletter.show()',1500));
					//animate.setMessage(data);
					/*
					$('#newsletter .message').html('<p>There\'s some erros on your form</p>');

					for(var i in data.fields)
					{
						$('#newsletter').find('.error-' + i).html(data.fields[i]);
					}
					*/
				}
				
			});
			
		}
		
	}
		
}

var comment = {
		
	isSending : false,
	
	show : function()
	{

		email.hide();
		newsletter.hide();
		content.hide();

		$('#comment').hide().find('span').html('');
		$('#comment input, #comment textarea').val('');
		$('#comment .message').html('');
		elPos.commentBox();
		$('#comment').css({'visibility':'visible'});
		$('#comment').show();
		$('input[name=name').focus();
		
	},
	
	hide : function(visibility)
	{
		if(visibility==true){
			$('#comment').css({'visibility':'hidden'});
			}else{
		$('#comment').hide();
			}
	},
	
	send : function()
	{
					
		if (comment.isSending == false)
		{
			comment.hide(true);
			animate.setMessage('Sending Comment...');
			//$('#comment .message').html('<p>Sending...</p>');
			comment.isSending = true;
		
			$.post('home/comment/&' + $('#comment form').serialize(), function(data){
				
				$('#comment').find('span').html('');
				$('#comment .message').html('');
				comment.isSending = false;
				
				if (data.sucess)
				{
					/*
					$('#comment .message').html('<p>Your email was sent!</p>');
					$('#comment').find('span').html('');
					*/
					comment.hide();
					animate.setMessage('Comment Sent! Thanks!');
					
				}else{
					//animate.setMessage('THERE\'S SOME ERRORS ON YOUR FORM');
					animate.setMessage('Error!','',setTimeout('comment.show()',1500));
					//$('#comment .message').html('<p>There\'s some erros on your form</p>');

					for(var i in data.fields)
					{
						//$('#comment').find('.error-' + i).html(data.fields[i]);
					}
				}
				
			});
			
		}
		
	}
		
}

var content = {

	isLoading : false,

	font : 12,
	
	get : function(what)
	{
		
		$('#content > div').remove();
		$('#content').append('<div class="pane"></div>');
	
		if (!content.isLoading)
		{
			
			zGal.stopGallery();
			
			content.isLoading = true;
			
			$.get('home/content/' + what, function(data){
				
				zGal.stopShowLoadingImg();
				newsletter.hide();
				email.hide();
				comment.hide();
								
				$('#holder div img').fadeOut('slow', function(){
					$(this).remove();
				
				
				
				zGal.currentImgWidth = 50;
				zGal.currentImgHeight = 50;
				zGal.resizeImage();
				});				
								
				$('#holder div').append($('<img src="' + zGal.baseUrl + 'img/gallery-thumbs.jpg" />').addClass('current'));
				animate.galleryHide();
				animate.hideToolBox();
				
				//animate.hideMinimumMenuRight();
				//animate.hideMenuRight();
				
				content.isLoading = false;
			
				//$('#content, #content-bg').show();
				$('#content').show();
				
				$('#content .pane').html(data.msg).jScrollPane({scrollbarWidth:10, dragMinHeigh:23, dragMaxHeight: 380});
				
				elPos.contentBox();
				
			});
		}
		
	},
	
	hide : function()
	{
		content.font = 12;
		$('#content').hide();
		//$('#content, #content-bg').hide();
	},
	
	zoomIn : function()
	{
		if (content.font >= 20)
		{
			content.font = 19;
		}
		
		content.font++;
		
		$('.pane, .pane *').css({'font-size' : content.font+'px'});  
		$('#content .pane').jScrollPane({scrollbarWidth:10, dragMinHeigh:23, dragMaxHeight: 380});
		
	},
	
	zoomOut : function()
	{
		if (content.font <= 13)
		{
			content.font = 13;
		}
		
		content.font--;
		$('.pane, .pane *').css({'font-size' : content.font+'px'});  
		$('#content .pane').jScrollPane({scrollbarWidth:10, dragMinHeigh:23, dragMaxHeight: 380});
		
	}
	
	
}

var elPos = {

	toolBox : function()
	{
		var ww = $(window).width();
		$('#toolbox').css({left: (ww-590) / 2});
	},
	
	emailBox : function()
	{
		var ww = $(window).width(), wh = $(window).height();
		var t = $('#toolbox').css('marginTop').replace('px', '').replace('-', '') == 0 ? -50 : 25;
		$('#email').css({top: (wh-$('#email').innerHeight()-(50 + t)) / 2, left: (ww-$('#email').innerWidth()) / 2});
	},
	
	newsletterBox : function()
	{
		var ww = $(window).width(), wh = $(window).height();
		var t = $('#toolbox').css('marginTop').replace('px', '').replace('-', '') == 0 ? -50 : 25;
		$('#newsletter').css({top: (wh-$('#newsletter').innerHeight()-(50 + t)) / 2, left: (ww-$('#newsletter').innerWidth()) / 2});
	},
	
	commentBox : function()
	{
		var ww = $(window).width(), wh = $(window).height();
		var t = $('#toolbox').css('marginTop').replace('px', '').replace('-', '') == 0 ? -50 : 25;
		$('#comment').css({top: (wh-$('#comment').innerHeight()-(50 + t)) / 2, left: (ww-$('#comment').innerWidth()) / 2});
	},
		
	leftMenu : function(callback)
	{
		var wh = $(window).height();
		$('#left-menu-opened, #left-menu-opened div.container-menu').height(wh - 206);
		//$('#left-menu-opened div.close-menu').css({top: ((wh-22) / 2) - 25}).show();
		$('#left-menu-opened div.close-menu').height(wh-50).show();
		
		$('#left-menu-closed, #left-menu-closed div.container-menu').height(wh);
		//*$('#left-menu-closed div.open-menu').css({top: ((wh-24) / 2) - 25});
		$('#left-menu-closed div.open-menu').height(wh-50);
	
		setTimeout(function(){
			typeof(callback) == 'function' ? callback.call() : '';
		}, 500);
		
	},
	
	contentBox : function()
	{
		var ww = $(window).width(), wh = $(window).height();
		$('#content').css({top: (wh-$('#content').innerHeight()-50) / 2, left: (ww-$('#content').innerWidth()) / 2});
		$('#content-bg').width(ww).height(wh);
	},
	
	rightMenu : function(callback)
	{
		
		var wh = $(window).height();
		var mt = (wh - 132 - parseInt($('#right-menu-opened div.thumbs').css('height').replace('px', ''))) / 2;
		
		if ($('#right-menu-opened div.thumbs').css('height').replace('px', '') == 'auto')
		{
			mt = 0;
		}
		
		$('#right-menu-opened div.container-menu').css({paddingTop: mt});
		$('#right-menu-opened div.container-menu').height(wh - mt);
		$('#right-menu-opened div.close-menu').height(wh-50).show();
		
		$('#right-menu-closed, #right-menu-closed div.container-menu').height(wh);
		$('#right-menu-closed div.open-menu').height(wh-50);
	
		setTimeout(function(){
			typeof(callback) == 'function' ? callback.call() : '';
		}, 500);
		
	},
	
	footer : function()
	{
		
		$('#footer').css({top:$(window).height() - 50}).show();
		
		var dfw = $('#footer').innerWidth();
		var dfrw = $('#footer div.fr').innerWidth() + 50;
		var w = dfw - dfrw;
		w = w <= 0 ? w : w; 
		
		$('#footer div.fl').width(w);
		
	},
	
	footerContent : function()
	{
		var p = $('#footer div.fr p.fl');
		p.css({marginTop: (50 - p.height())/2});
		p = $('#footer div.fl p');
		p.css({marginTop: (50 - p.height())/2});
	},
	
	galleryThumbsCenter : function()
	{
		var wh = $(window).height(), ww = $(window).width();
		$('#gallery-holder').css({top: ((wh - $('#gallery-holder').height() - 50)/2), left: ((ww - $('#gallery-holder').width())/2)});
	}
		
};

var toolBox = {
	
	isPlaying 	: false,
	isNext 		: false,
	isPrev		: false,
	isAmplied 	: false,
	isVisible	: false,	
	play : function()
	{
		$('body').unbind('mousemove');
	
		if (!toolBox.isPlaying)
		{
			$('#toolbox li.play a').addClass('opened dr');
			toolBox.isPlaying = true;
			zGal.currentGalleryIsOpen = false;
			zGal.currentGalleryStop = false;
			zGal.galleryAutoPlay(zGal.currentGalleryName, 5000);
			animate.galleryHide();
		}else{
			$('#toolbox li.play a').removeClass('opened dr');
			toolBox.isPlaying = false;
			zGal.currentGalleryIsOpen = true;
			zGal.stopGallery();
			//animate.hideMenuRight(animate.showMinimumMenuRight());
			//zGal.prepareCategoryCenter();
		}
	},
	
	next : function()
	{
		$('#toolbox li.play a').removeClass('opened dr');
		
		$('body').unbind('mousemove');
		toolBox.isPlaying = false;
		zGal.stopGallery();
		animate.galleryHide();
		animate.hideMenuRight(animate.showMinimumMenuRight());
		index = zGal.currentGalleryIndex > (zGal.currentGalleryTotal - 1) ? 0 : zGal.currentGalleryIndex;
		index = index < 0 ? 0 : index;
		zGal.currentGalleryIndex 	= (zGal.currentGalleryIndex + 1) > (zGal.currentGalleryTotal) ? 0 : zGal.currentGalleryIndex + 1;
		zGal.currentGalleryIndex	= zGal.currentGalleryIndex == 0 && index == 0 ? 1 : zGal.currentGalleryIndex;
		zGal.currentImgWidth  		= zGal.gallery[zGal.currentGalleryName][index][0];
		zGal.currentImgHeight 		= zGal.gallery[zGal.currentGalleryName][index][1];
		zGal.showImage(zGal.gallery[zGal.currentGalleryName][index]['imgNormal'], zGal.currentGalleryName);
		zGal.currentGalerySelectedImage=unescape(zGal.gallery[zGal.currentGalleryName][index]['imgThumbFile'].src);
		//alert(zGal.currentGalerySelectedImage)
		
		
		
		$(".thumbs ul li.selecionado").attr('class','');
		$(".thumbs ul li").each(function(){
										 //alert($(this).find("img").attr("src"))
						if($(this).find("img").attr("src")==zGal.currentGalerySelectedImage){
													$(this).attr("class","selecionado");
													$(this).parents("ul").attr("class","selParent");
													var dif =$(this).parents("ul").position().top - $(this).position().top;
													//alert(dif);
													$(this).parents("ul").animate({marginTop:'+=' + dif});
													//alert("selecionado;" + $(this).position().top + " lista:" + $(this).parents("ul").position().top);
						}
						})
		
		toolBox.isNext = true;
	}, 
	
	prev : function()
	{
		$('#toolbox li.play a').removeClass('opened dr');
		$('body').unbind('mousemove');
		
		zGal.currentGalleryIndex--;
		toolBox.isPlaying = false;
		zGal.stopGallery();
		animate.galleryHide();
		animate.hideMenuRight(animate.showMinimumMenuRight());
		index = (zGal.currentGalleryIndex - 1) < 0 ? (zGal.currentGalleryTotal - 1) : zGal.currentGalleryIndex - 1;
		zGal.currentGalleryIndex 	= index + 1;
		zGal.currentImgWidth  		= zGal.gallery[zGal.currentGalleryName][index][0];
		zGal.currentImgHeight 		= zGal.gallery[zGal.currentGalleryName][index][1];
		zGal.showImage(zGal.gallery[zGal.currentGalleryName][index]['imgNormal'], zGal.currentGalleryName);
		zGal.currentGalerySelectedImage=unescape(zGal.gallery[zGal.currentGalleryName][index]['imgThumbFile'].src);
		$(".thumbs ul li.selecionado").attr('class','');
		$(".thumbs ul li").each(function(){
										 //alert($(this).find("img").attr("src"))
						if($(this).find("img").attr("src")==zGal.currentGalerySelectedImage){
													$(this).attr("class","selecionado");
													$(this).parents("ul").attr("class","selParent");
													var dif =$(this).parents("ul").position().top - $(this).position().top;
													//alert(dif);
													$(this).parents("ul").animate({marginTop:'+=' + dif});
													//alert("selecionado;" + $(this).position().top + " lista:" + $(this).parents("ul").position().top);
						}
						})
toolBox.isPrev = true;
	},
	toggleZoom					:	function(){
		if (toolBox.isAmplied){			
			toolBox.zoomOut();
			return false;
			}else{				
				toolBox.zoomIn();
			return false;
				}
		
		},
	thumbs : function()
	{
		$('#toolbox li.play a').removeClass('opened dr');
		$('body').unbind('mousemove');
		
		$('#holder div img').fadeOut('slow', function(){
			$(this).remove();
		});
		$('#holder div').append($('<img src="' + zGal.baseUrl + 'img/gallery-thumbs.jpg" />').addClass('current'));
		zGal.currentImgWidth = 50;
		zGal.currentImgHeight = 50;
		zGal.resizeImage();
		
		toolBox.isPlaying = false;
		zGal.stopGallery();
		animate.galleryShow();
		animate.hideMenuRight(animate.showMinimumMenuRight());
	},
	
	like : function()
	{
		$('#toolbox li.like a').addClass('opened dr');
		var index 	= zGal.currentGalleryIndex == 0 ? zGal.currentGalleryIndex : zGal.currentGalleryIndex - 1;
		var id 		= zGal.gallery[zGal.currentGalleryName][index][5];
		
		animate.setMessage('You liked it! Thanks!');
		
		$.get('home/like/' + id);
		
	},
	
	emailImage : function()
	{
		email.show();
	},
	
	addLightBox : function()
	{
		$('#toolbox li.lightbox a').addClass('opened dr');
		var index 	= zGal.currentGalleryIndex == 0 ? zGal.currentGalleryIndex : zGal.currentGalleryIndex - 1;
		var id 		= zGal.gallery[zGal.currentGalleryName][index][5];
		
		animate.setMessage('Image on lightbox!');
		
		$.get('home/addLb/' + id, function(data)
		{
			console.log(data);
		});
	},
	
	/* ------------------------------------------ */ 
	
	zoomIn : function()
	{
		toolBox.isAmplied=true;
		zGal.wasLeftMenuOpened=zGal.isLeftMenuOpen()
		zGal.wasRightMenuOpened=zGal.isRightMenuOpen()
		
		$('#toolbox li.zoom-out').addClass('opened').removeClass('zoomout');
		$('#toolbox li.zoom-in').addClass('zoomin').find('a').removeClass('opened');
		$('#toolbox li.play a').removeClass('opened dr');
		zGal.closeRightMenu()
		zGal.closeLeftMenu()
		
		var 
			ww 		= $(window).width(),
			wh 		= $(window).height() - 50,
			imgW 	= zGal.currentImgWidth,
			imgH 	= zGal.currentImgHeight,
			cImgW 	= $('#holder').find('img.current').width(),
			cImgH 	= $('#holder').find('img.current').height();
			
		if (((cImgH == wh | cImgW == ww) | (cImgW > 50 && cImgH > 50) ) && (imgH > wh | imgW > ww))
		{
			
			zGal.stopGallery();
			animate.galleryHide();
			animate.hideMenuRight(animate.showMinimumMenuRight());
			
			var img = $('#holder').find('img.current');
			
			//img.animate({ top: ((wh - imgH)/2), height:parseInt(imgH), width:parseInt(imgW), left: ((ww - imgW)/2)});
			img.animate({height:parseInt(imgH), width:parseInt(imgW), left: ((ww - imgW)/2), top: ((wh - imgH)/2)}, "slow",function(){
			
			$('body').bind('mousemove', function(e){
				
				var dX = e.pageX;
				var dY = e.pageY;
				
				var imgLeft = parseInt(img.css('left').replace('px'));
				var imgTop 	= parseInt(img.css('top').replace('px'));
				
				var vLeftRight = ((ww - imgW)/2) / ww;
				var vUpDown = ((wh - imgH)/2) / wh;
				
				if (imgW > ww)
				{
				
					// right
					if (dX > zGal.dX)
					{
						
						if (dX != zGal.dX)
						{
							var mL = (vLeftRight * dX) * 2;
							img.css({left:mL});
						}
						
					// left
					}else{
						if (dX != zGal.dX)
						{
							var mL = (vLeftRight * dX) * 2;
							img.css({left:mL});
						}
					}
					
				}
				
				if (imgH > wh && dY <= wh)
				{
				
					// bottom
					if (dY > zGal.dY)
					{
						if (dY != zGal.dY)
						{
							var mT = (vUpDown * dY) * 2;
							img.css({top:mT});
						}
						
					// top
					}else{
						if (dY != zGal.dY)
						{
							var mT = (vUpDown * dY) * 2;
							img.css({top:mT});
						}
					}
					
				}
				
				zGal.dX = dX;
				zGal.dY = dY;
			});
			});
		}
		
	},
	
	zoomOut : function()
	{
		toolBox.isAmplied=false;
		if(zGal.wasLeftMenuOpened){
			zGal.openLeftMenu()
			}else{
				zGal.closeLeftMenu()
				}
			
		if(zGal.wasRightMenuOpened){
			zGal.openRightMenu()
		}else{
			zGal.closeRightMenu()
			}
		$('#toolbox li.zoom-in').addClass('opened').removeClass('zoomin').find('a').removeClass('opened');
		$('#toolbox li.zoom').find('a').removeClass('opened');
		$('#toolbox li.zoom-out').addClass('zoomout').find('a').removeClass('opened');
		$('#toolbox li.play a').removeClass('opened dr');
		
		$('body').unbind('mousemove');
		
		$('body').css({cursor:'default'});
		zGal.resizeImage();
	}
	
};

var animate = {
	
	showToolBox : function(callback)
	{
		toolBox.isVisible=true
		$('#toolbox').animate({top:0},function(){
						typeof(callback) == 'function' ? callback.call() : '';					   
											   
											   });
	},
	
	hideToolBox : function()
	{
		toolBox.isVisible=false
		$('#toolbox').animate({top:-50});
	},
		
	/* ---------------------------------------- */	
		
	hideMenu : function(callback){
		$('#left-menu-opened').animate({left:'-203'}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	showMenu : function(callback)
	{
		$('#left-menu-opened').animate({left:0}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	/* ---------------------------------------- */
	
	hideMenuRight : function(callback){
		$('#right-menu-opened').animate({right:'-197'}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	showMenuRight : function(callback)
	{
		$('#right-menu-opened').animate({right:0}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	/* ---------------------------------------- */
	
	showMinimumMenu : function(callback)
	{
		$('#left-menu-closed').animate({left:0}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	hideMinimumMenu : function(callback)
	{
		$('#left-menu-closed').animate({left:'-66'}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	/* ---------------------------------------- */
	
	showMinimumMenuRight : function(callback)
	{
		$('#right-menu-closed').animate({right:0}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	hideMinimumMenuRight : function(callback)
	{
		$('#right-menu-closed').animate({right:'-85'}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	/* ---------------------------------------- */
	
	galleryHide : function()
	{
		$('#gallery-holder').hide(0);
	},
	
	galleryShow : function()
	{
		$('#gallery-holder').show(0);
	},
	
	/* ---------------------------------------- */
	
	showFooter : function(callback)
	{	
		$('#footer').animate({top:$(window).height() - 50}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	hideFooter : function(callback)
	{	
		$('#footer').animate({top:$(window).height()}, function(){
			typeof(callback) == 'function' ? callback.call() : '';
		});
	},
	
	setMessage : function(html,callback,realCallback)
	{
		$('#message').html('<p>' + html + '</p>').removeAttr('style');
		$('#message').css({top: ($(window).height()-$('#message').innerHeight()) / 2, left: ($(window).width()-$('#message').innerWidth()) / 2}).fadeIn("fast",function(){
						typeof(callback) == 'function' ? callback.call() : '';																																				
																																										});
		setTimeout(function(){
			typeof(realCallback) == 'function' ? $('#message').fadeOut(1000, realCallback) : $('#message').fadeOut(1000);
		}, 2000)
		
	}
};

var is = {
	varBusy : false,
	busy : function ()
	{
		return !is.varBusy;
	}
}

$(window).bind('resize', function(){
	/**
	 * Positions binds
	 */
	zGal.resizeImage();
	zGal.loadingImgPos();
	elPos.leftMenu();
	elPos.rightMenu();
	elPos.footer();
	elPos.galleryThumbsCenter();
	//zGal.adjustCategoryCenter();
    if (zGal.currentGalleryIsOpen)
    {
        $('#gallery-holder').hide(0, function(){
            zGal.resize2();
        });
    }
	zGal.adjustCategoryRight();
	elPos.toolBox();
	elPos.emailBox();
	elPos.newsletterBox();
	elPos.contentBox();
	toolBox.zoomOut();
	$('body').unbind('mousemove');
	$('body').width($(window).width()).height($(window).height());
});

//$(function(){
function init() {
	$('body').width($(window).width()).height($(window).height());
	 $("img").each(function() { 
               this.onselectstart = function() { return false; };
            });

	/**
	 * Positions binds
	 */
	 $(function() {
            $(this).bind("contextmenu", function(e) {
                e.preventDefault();
            });
        }); 
	zGal.loadingImgPos();
	elPos.leftMenu();
	elPos.toolBox();
	elPos.rightMenu();
	elPos.galleryThumbsCenter();
	elPos.footer();
	elPos.footerContent();
	elPos.emailBox();
	elPos.newsletterBox();
	elPos.contentBox();
	/**
	 * Left Menu Bind open close
	 */
	$('#left-menu-opened div.close-menu').click(function(){
		animate.hideMenu(function(){animate.showMinimumMenu()});
	});
	
	$('#left-menu-closed div.open-menu').click(function(){
		animate.hideMinimumMenu(function(){animate.showMenu()});
	});
	$('.close-menu').hover(function(){
													  $(this).parents('.container-menu').addClass('bordaLaranja');
													  },
											function(){
													$(this).parents('.container-menu').removeClass('bordaLaranja');

												})
	
	/* -------------------------------------------------------------- */
	
	/**
	 * Right Menu Bind open close
	 */
	
	$('#right-menu-opened div.close-menu').click(function(){
		animate.hideMenuRight(function(){animate.showMinimumMenuRight()});
	});
	
	$('#right-menu-closed div.open-menu').click(function(){
		animate.hideMinimumMenuRight(function(){animate.showMenuRight()});
	});
	
	$("#holder, #holder img.current").live("click",function(){
								if(($("#holder img.current").is(":visible")) && ($("#toolbox").css("top").replace('px','')==0)){
									   toolBox.toggleZoom();
								}
									   
									   })

	
	/* -------------------------------------------------------------- */
	
	/**
	 * Left Menu 
	 */
	 /*$('.menuPrin').click(function(){
			$(this).addClass('style','color:#FF5500');					   
			$('.menuPrin').not($(this)).each(function(){
				//$(this).removeClass('opened').next('ul').hide();
				$(this).attr('style','color:#fff');
			})					   
								   })*/
	$('.has-sub, .menuPrin').click(function(){
		if (is.busy())
		{


			$(this).removeAttr('style');
			if($(this).has("ul")){
			$(this).next('ul').toggle();

			$(".no-sub").each(function(){
				$(this).removeClass('opened');
									   })

			}
			$(this).toggleClass('opened');

			/*$('.menuPrin').not($(this)).each(function(){
				//$(this).removeClass('opened').next('ul').hide();
				$(this).attr('style','color:#fff!important');
			})*/

		}
	});
	$(".no-sub").click(function(){
								//alert('oi');
                                $('.has-sub').next().find('p').removeClass('opened');
								$(this).addClass('opened');
								})

    $('.has-sub').next().find('p').click(function() {
        $(".no-sub").each(function(){
				$(this).removeClass('opened');
									   })
    });
	
	/**
	 * Left Menu Hover
	 */
	 
	/*$('#left-menu-opened ul.fr > li > ul > li > p').click(function(){
			$(this).parents("ul.fr").siblings("ul.fr").find(".menuPrin").attr('style','color:#fff')													   
			$(this).parents("ul.fr").find(".menuPrin").removeAttr('style')	
			
																   
																   })*/
	$('#left-menu-opened ul.fr > li > p').not('.opened').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	/**
	 * Categories
	 */
	$('#left-menu-opened ul.fr > li ul > li > p').not('.opened').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	}).click(function(){
		if (!$(this).hasClass('opened'))
		{
			$(this).toggleClass('opened');
			
			$('#left-menu-opened ul.fr > li ul > li > p').not($(this)).each(function(){
				$(this).removeClass('opened');
			})
			
		}
	});
	
	/* -------------------------------------------------------------- */
	
	/** 
	 * Gallery Center up function
	 */
	$('#gallery-top div').hover(function(){
		if (!$(this).hasClass('no'))
		{
			$(this).addClass('over');
		}
	}, function(){
		$(this).removeClass('over');
	}).click(function(){
		zGal.categoryCenterUp();
	});

	/** 
	 * Gallery Center down function
	 */
	$('#gallery-bottom div').hover(function(){
		if (!$(this).hasClass('no'))
		{
			$(this).addClass('over');
		}
	}, function(){
		$(this).removeClass('over');
	}).click(function(){
		zGal.categoryCenterDown();
	});
	
	/* -------------------------------------------------------------- */
	
	/** 
	 * Gallery Right up function
	 */
	$('#right-menu-opened .up').hover(function(){
		if (!$(this).hasClass('no'))
		{
			$(this).addClass('over');
		}
	}, function(){
		$(this).removeClass('over');
	}).click(function(e){
		e.preventDefault();
		zGal.categoryRightUp();
		return false;
	});

	/** 
	 * Gallery Right down function
	 */
	$('#right-menu-opened .down').hover(function(){
		if (!$(this).hasClass('no'))
		{
			$(this).addClass('over');
		}
	}, function(){
		$(this).removeClass('over');
	}).click(function(e){
		e.preventDefault();
		zGal.categoryRightDown();
		return false;
	});
	
	/* -------------------------------------------------------------- */
	
	/**
	 * Block page scroll
	 */
	$(window).scroll(function(){ 
		window.scroll(0,0);
		return false;
	});

	/* ToolBox */
	$('#toolbox li.prev').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	
	$('#toolbox li.play').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	
	$('#toolbox li.next').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	
	$('#toolbox li.zoom-out').hover(function(){
		if ($(this).hasClass('zoomout'))
		{
			$('#toolbox li.zoom a').addClass('opened');
			$(this).find('a').addClass('opened');
		}
	}, function(){
		if ($(this).hasClass('zoomout'))
		{
			if (!$(this).find('a').hasClass('dr'))
			{
				$('#toolbox li.zoom a').removeClass('opened');
				$(this).find('a').removeClass('opened');
			}
		}
	});
	
	$('#toolbox li.zoom-in').hover(function(){
		if ($(this).hasClass('zoomin'))
		{
			if (!$('#toolbox li.zoom-out').hasClass('opened'))
			{
				$('#toolbox li.zoom a').addClass('opened');
			}
			$(this).find('a').addClass('opened');
		}
	}, function(){
		if ($(this).hasClass('zoomin'))
		{
			if (!$(this).find('a').hasClass('dr'))
			{
				if (!$('#toolbox li.zoom-out').hasClass('opened'))
				{
					$('#toolbox li.zoom a').removeClass('opened');
				}
				$(this).find('a').removeClass('opened');
			}
		}
	});
	
	$('#toolbox li.email').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	
	$('#toolbox li.like').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	
	$('#toolbox li.lightbox').hover(function(){
		$(this).find('a').addClass('opened');
	}, function(){
		if (!$(this).find('a').hasClass('dr'))
		{
			$(this).find('a').removeClass('opened');
		}
	});
	/* ToolBox */
	
	$('#email .cancel').click(function(){
		email.hide();
	});
	$('#email .send').click(function(){
		email.send();
	});
	
	$('#newsletter .send').click(function(){
		newsletter.send();
	});
	$('#newsletter .cancel').click(function(){
		newsletter.hide();
	});
	
	$('#comment .send').click(function(){
		comment.send();
	});
	$('#comment .cancel').click(function(){
		comment.hide();
	});
	
	$('*').dblclick(function(e){
		e.preventDefault();
		return false;
	});
	
	$(document).keydown(function(e){
	    if (e.keyCode == 39)
	    { 
	       toolBox.next();
	       return false;
	    }
	    if (e.keyCode == 37)
	    { 
	       toolBox.prev();
	       return false;
	    }
	});

	$('li.blogger').hover(function(){
		$(this).css({background:'url(\'img/blogger.png\')'});
	}, function(){
		$(this).css({background:'url(\'img/blogger-off.png\')'});
	});
	$('li.blogger').click(function(){
								   animate.setMessage("The blog will be available soon!");
								   })
	$('li.facebook').hover(function(){
		$(this).css({background:'url(\'img/facebook.png\')'});
	}, function(){
		$(this).css({background:'url(\'img/facebook-off.png\')'});
	});
	
	$('li.twitter').hover(function(){
		$(this).css({background:'url(\'img/twitter.png\')'});
	}, function(){
		$(this).css({background:'url(\'img/twitter-off.png\')'});
	});
	
	$('li.linkedin').hover(function(){
		$(this).css({background:'url(\'img/linkedin.png\')'});
	}, function(){
		$(this).css({background:'url(\'img/linkedin-off.png\')'});
	});
		setTimeout("$('.upgWrapper,.upgLoad, #imgLoader').each(function(){$(this).fadeOut('slow')} )",5000);
}
//});




