	$(document).ready(function(){
	
	/* Image Banner */
	
		noImages = $("#header-image-banner .header-image-item").length;
		counter = 0 ;
		imagePos = 0;
		
		
		/* SET IMAGE POSITIONING */    
		
		c = 0;
		for(i=noImages;i>=0;i--) {            
			$("#header-image-banner .header-image-item:eq("+c+")").css("z-index", i );    
			c++;
		}     
		
			/* SET NAV */   
			
		if ($('#header-image-banner .header-image-item').length > 1) {
			$('#header-image-banner-nav').append('<span class="prev"></span>') ;
			$('#header-image-banner-nav').append('<a href="#" class="cur-image">1</a>') ;
			$('#header-image-banner-nav').append('<span>/</span>') ;
			$('#header-image-banner-nav').append('<a href="#" class="total-images">'+noImages+'</a>') ;
			$('#header-image-banner-nav').append('<span class="next"></span>') ;
		}
				
		
		
		function timer(count) {
			
			playId = setTimeout(function(){    
			
				newPos = counter + 1;
				
				$("#header-image-banner .header-image-item").removeClass("currentImage");
				
				$("#header-image-banner .header-image-item:eq("+counter+")").fadeOut('slow');
				
				$("#header-image-banner .header-image-item:eq("+newPos+")").fadeIn('slow', function() {
																	
				}).addClass("currentImage"); 
				
				counter ++;
					
				// reset
				if (counter == noImages) {                
					counter = 0;
					$("#header-image-banner .header-image-item:eq("+noImages+")").fadeOut('slow');
					$("#header-image-banner .header-image-item:eq(0)").fadeIn('slow');
				}
				
				$('#header-image-banner-nav a.cur-image').text(counter+1);  
				
				imagePos = counter;  
									  
				timer(imagePos);
				
				//}, 4000);  
			}, 4000);  
						
	
		}
		
		$('#header-image-banner-nav .prev').click(function(){
		
			
			if (counter > 0) {
	
				clearTimeout(playId);
				
				imagePos = counter;	
				imagePosNew = imagePos -1;
				
				$("#header-image-banner .header-image-item").removeClass("currentImage");
				
				$("#header-image-banner .header-image-item:eq("+imagePos+")").fadeOut(1000);
				$("#header-image-banner .header-image-item:eq("+imagePosNew+")").fadeIn(1000).addClass("currentImage"); 
				
				$('#header-image-banner-nav a.cur-image').text(imagePos);	
				
				counter = imagePosNew;
				timer();
				
			}
	

    })



    $('#header-image-banner-nav .next').click(function(){
								   
	
		//console.log(imagePos, noImages);
	
		if (counter < noImages-1) {

			clearTimeout(playId);
			
			imagePos = counter;			
			imagePosNew = imagePos +1;
					
			$("#header-image-banner .header-image-item").removeClass("currentImage");
			
			$("#header-image-banner .header-image-item:eq("+imagePos+")").fadeOut(1000, function(){ 
			});
			
			$("#header-image-banner .header-image-item:eq("+imagePosNew+")").fadeIn(1000).addClass("currentImage"); 
			
			$('#header-image-banner-nav a.cur-image').text(imagePosNew+1);	
			
			counter = imagePosNew;
			timer();
			
			
		} 
	
		
    })     


	//init 
	
	if ($('#header-image-banner .header-image-item').length > 1) {
	
    	timer(); 
		//console.log("tester");
	}	

	/* drop down menu INIT */

   
	$('#top-menu li ul').css("display","none"); 
	
	 catBoxWidth = 150 + 20; //width + padding;  
	
	 $('#top-nav > li').hover(
	 
		 function(){
		 
			if ($(this).find("ul").length > 0) {
							
				$(this).find("ul:last li").css("border","none");				
				
				catBoxes = ($(this).find("ul").length -1);
				catBoxTotal = catBoxes * catBoxWidth;
				$(this).find("ul:first").css("width",catBoxTotal+"px");
				$(this).addClass("active");		
				$(this).find('ul').show();
				
			}
		 },
		 
		 function(){
			$(this).find('ul').hide();
			$(this).removeClass("active");
		 }
	 
	 )
	   

})
