var win_height = 0;
var win_width =  0;
var shiftSpeed = 1100;
var bigSlideWidth = 0;
var bigSlideHeight = 0;	
var columnCount = 3;
var rowCount = 3;


function shiftBoxes(boxN) {
		var col = ( (boxN) % rowCount ) * -1;
		var row = Math.floor( (boxN) / columnCount ) * -1;		
	
		$("#big-panel").stop().animate({ left: bigSlideWidth * col, top: bigSlideHeight * row }, shiftSpeed, "easeInOutSine"  );
		
} 	
	
$(document).ready(function(){

	win_height = parseInt( $(window).height()  );
	win_width =  parseInt( $(window).width() );
	shiftSpeed = 1100;
	bigSlideWidth = win_width ;
	bigSlideHeight = win_height;	
	columnCount = 3;
	rowCount = 3;

	faux_resize();
	function faux_resize()
	{		
		$('#enclosure').css( { 'height' : win_height + 'px', 'width' : win_width + 'px' } );
		$('#big-panel').css( { 
								'height' : ( win_height * 2 ) + 'px',
								'width'  : ( win_width  * 3 ) + 'px'			
							} );
		$('#big-panel .slide-wrap').css( { 
								'height' :  win_height + 'px',
								'width'  :  win_width  + 'px'			
							} );
		$('#viewport .afterwards p').css( { 						
								'width'  : win_width + 'px'			
							} );

	}
	
	shiftBoxes(0);

	
	var options = {
		target: '.contact_form',
		success: againform
	};
	

	$('#ajax_contact_form').ajaxForm(options); 
	
	function againform() {
		$('#ajax_contact_form').ajaxForm(options); 	    
	}
	
	$("div.nav a").click( function() { 		
		navIndex = $(this).attr('position');		
		shiftBoxes( navIndex  ); 
		return false;
	});
	
	$("map area").click( function() { 		
		navIndex = $(this).attr('position');				
		shiftBoxes( navIndex  ); 
		return false;
	});
	
	$("map area").mouseover(function(){
		//$(this).css('cursor', 'pointer');
		$(this).css('cursor', 'hand');
	});


	// Product Section JS
	
	if( $('#mycarousel ul li').length != 0  )
		$('#mycarousel').jCarouselLite({
					 	btnNext: ".next",
		        		btnPrev: ".prev",
						visible: 5,
						speed: 800
				});
	
	$('.product_click').click(
			function() {
				load_again( $(this) );
				return false;
			}
	);	

	function load_again(elem) {
		
	
		var pid = elem.attr('rel');					
		
		if( elem.find('.loading_image').length == 0 )
			var loader = $(".loading_image").clone().prependTo( elem ).show();			
		$.post(
			base_url + 'welcome/product_image_list/' + pid,
			{ 'time' : 'time'},
			function(data) {
				$('#ajax_product_content').html(data);
				if( $('#mycarousel ul li').length != 0  )
					$('#mycarousel').jCarouselLite({
							btnNext: ".next",
							btnPrev: ".prev",
							visible: 5,
							speed: 800
					});
					
				// clickable on image location
				clickable_function_on_image();
				
				/*
					Product List clicable again  
					I know about live() function bt that's useable only in jquery over 1.3.1 >
					and i don't have time to retest all plugin cause deadline have to meet :(
				*/
				
				$('.product_click').click(
						function() {
							load_again( $(this) );
							return false;
						}
				);	
				
				// elem.find('.loading_image').remove();
			}					
		);
	}
	
	
	// Product Clickable System 
	
	function clickable_function_on_image() 
	{
	
		$('.carousel_product_image').click(
			function()
			{
				var orig_image = $(this).siblings('.project_image_info').children('img.project_image_img');
				var orig_desc = $(this).siblings('.project_image_info').children('div.project_image_details');
				
				$('#product_click_carousel_image').fadeOut('slow', function(){
					$(this).attr('src', orig_image.attr('src') );
				});				
				$('#product_click_carousel_image').fadeIn('slow');
				
				$('#product_click_carousel_description').fadeOut('slow', function(){
					$(this).html(orig_desc.html() );
				});
				$('#product_click_carousel_description').fadeIn('slow');
			}
		);
	
	}
	
	clickable_function_on_image();  

});
 