
$(document).ready(function(){
//	$(".arrow_right").click(function(){
//		$(".gallery_scroller").animate({
//			left:"-906px"							   
//		});								 
//	});






	function slide(){
		$(".gallery_scroller").animate({
			left:"-906px"							   
		});								 
	}
	$(".arrow_right").click(function(){slide(100)});

	$("#products,#exports,#networks").click(function(){
		window.location = $(this).attr("url");								  
	});




            $(function() {
				/**
				* navR,navL are flags for controlling the albums navigation
				* first gives us the position of the album on the left
				* positions are the left positions for each of the 5 albums displayed at a time
				*/
                var navR,navL	= false;
				var first		= 1;
				var positions 	= {
					'0'		: 0,
					'1' 	: 227,
					'2' 	: 454,
					'3' 	: 683,
				}
				var $ps_albums 		= $('#ps_albums');
				/**
				* number of albums available
				*/
				var elems			= $ps_albums.children().length;
				var $ps_slider		= $('#ps_slider');
				
				/**
				* let's position all the albums on the right side of the window
				*/
				var hiddenRight 	= $(window).width() - $ps_albums.offset().left;
				$ps_albums.children('div').css('left',hiddenRight + 'px');
				
				/**
				* move the first 5 albums to the viewport
				*/
				$ps_albums.children('div:lt(5)').each(
					function(i){
						var $elem = $(this);
						$elem.animate({'left': positions[i] + 'px','opacity':1},800,function(){
							if(elems > 5)
								enableNavRight();
						});
					}
				);
				
				/**
				* next album
				*/
				$ps_slider.find('.next').bind('click',function(){
					if(!$ps_albums.children('div:nth-child('+parseInt(first+5)+')').length || !navR) return;
					disableNavRight();
					disableNavLeft();
					moveRight();
				});
				
				/**
				* we move the first album (the one on the left) to the left side of the window
				* the next 4 albums slide one position, and finally the next one in the list
				* slides in, to fill the space of the first one
				*/
				function moveRight () {
					var hiddenLeft 	= $ps_albums.offset().left + 163;
					
					var cnt = 0;
					$ps_albums.children('div:nth-child('+first+')').animate({'left': - hiddenLeft + 'px','opacity':0},500,function(){
							var $this = $(this);
							$ps_albums.children('div').slice(first,parseInt(first+4)).each(
								function(i){
									var $elem = $(this);
									$elem.animate({'left': positions[i] + 'px'},800,function(){
										++cnt;
										if(cnt == 4){
											$ps_albums.children('div:nth-child('+parseInt(first+5)+')').animate({'left': positions[cnt] + 'px','opacity':1},500,function(){
												//$this.hide();
												++first;
												if(parseInt(first + 4) < elems)
													enableNavRight();
												enableNavLeft();
											});
										}		
									});
								}
							);		
					});
				}
				
				/**
				* previous album
				*/
				$ps_slider.find('.prev').bind('click',function(){
					if(first==1  || !navL) return;
					disableNavRight();
					disableNavLeft();
					moveLeft();
				});
				
				/**
				* we move the last album (the one on the right) to the right side of the window
				* the previous 4 albums slide one position, and finally the previous one in the list
				* slides in, to fill the space of the last one
				*/
				function moveLeft () {
					var hiddenRight 	= $(window).width() - $ps_albums.offset().left;
				
					var cnt = 0;
					var last= first+4;
					$ps_albums.children('div:nth-child('+last+')').animate({'left': hiddenRight + 'px','opacity':0},500,function(){
							var $this = $(this);
							$ps_albums.children('div').slice(parseInt(last-5),parseInt(last-1)).each(
								function(i){
									var $elem = $(this);
									$elem.animate({'left': positions[i+1] + 'px'},800,function(){
										++cnt;
										if(cnt == 4){
											$ps_albums.children('div:nth-child('+parseInt(last-5)+')').animate({'left': positions[0] + 'px','opacity':1},500,function(){
												//$this.hide();
												--first;
												enableNavRight();
												if(first > 1)
													enableNavLeft();
											});
										}										
									});
								}
							);
					});
				}
				
				/**
				* disable or enable albums navigation
				*/
				function disableNavRight () {
					navR = false;
					$ps_slider.find('.next').addClass('disabled');
				}
				function disableNavLeft () {
					navL = false;
					$ps_slider.find('.prev').addClass('disabled');
				}
				function enableNavRight () {
					navR = true;
					$ps_slider.find('.next').removeClass('disabled');
				}
				function enableNavLeft () {
					navL = true;
					$ps_slider.find('.prev').removeClass('disabled');
				}		
				
				
            });
			
			$(".emt1,.emt2,.emt3,.emt4,.emt5,.emt6,.emt7,.emt8,.emt9,.emt10,.emt11,.emt12").click(function(){
				window.location = $(this).attr("url");																							   
			});

			$(".emt1").mouseenter(function(){
				$(".pop1").fadeIn();							   
			}).mouseout(function(){
				$(".pop1").fadeOut();						
				});
			
			$(".emt2").mouseenter(function(){
				$(".pop2").fadeIn();							   
			}).mouseout(function(){
				$(".pop2").fadeOut();						
				});
			$(".emt3").mouseenter(function(){
				$(".pop3").fadeIn();							   
			}).mouseout(function(){
				$(".pop3").fadeOut();						
				});
			$(".emt4").mouseenter(function(){
				$(".pop4").fadeIn();							   
			}).mouseout(function(){
				$(".pop4").fadeOut();						
				});
			$(".emt5").mouseenter(function(){
				$(".pop5").fadeIn();							   
			}).mouseout(function(){
				$(".pop5").fadeOut();						
				});
			$(".emt6").mouseenter(function(){
				$(".pop6").fadeIn();							   
			}).mouseout(function(){
				$(".pop6").fadeOut();						
				});
			$(".emt7").mouseenter(function(){
				$(".pop7").fadeIn();							   
			}).mouseout(function(){
				$(".pop7").fadeOut();						
				});
			$(".emt8").mouseenter(function(){
				$(".pop8").fadeIn();							   
			}).mouseout(function(){
				$(".pop8").fadeOut();						
				});
			$(".emt9").mouseenter(function(){
				$(".pop9").fadeIn();							   
			}).mouseout(function(){
				$(".pop9").fadeOut();						
				});
			$(".emt10").mouseenter(function(){
				$(".pop10").fadeIn();							   
			}).mouseout(function(){
				$(".pop10").fadeOut();						
				});
			$(".emt11").mouseenter(function(){
				$(".pop11").fadeIn();							   
			}).mouseout(function(){
				$(".pop11").fadeOut();						
				});
			$(".emt12").mouseenter(function(){
				$(".pop12").fadeIn();							   
			}).mouseout(function(){
				$(".pop12").fadeOut();						
				});
			


//Gallery	
	$(".g_empty").hover(function(){
		$(this).append("<div class='ps_desc'>" + "</div>");
		$(".ps_desc").text($(this).attr("title"));
		},function(){
			$(".ps_desc").fadeOut(200);
			
			});





});
