
	
	$(document).ready(function(){
		
		cookie_name = 'parabureau_web_menu_link_index';
		
		// contact link
		if( $("#page_23").length ){
			
			// append contact link
			$("BODY").append('<a href="mailto:info@parabureau.com" id="contact_link"></a>');
			
		}
		
		// clear cookie
		// alert($(".resizable_panel").length);
		// if( !$(".resizable_panel").length ){ eraseCookie(cookie_name); }
		
		// find opened link index
		active_link_link = $("DIV#p_menu DIV#topmenu_panel A").index($("DIV#p_menu DIV#topmenu_panel A.active"));
	
		//alert("current index:"  + active_link_link);
		if( active_link_link == -1 ){ 
			
			// try cookie
			if( readCookie(cookie_name) ){ active_link_link = readCookie(cookie_name); /*alert("cookie:"  + active_link_link);*/ } 
			else active_link_link = 0;
			 
		}

		//alert("using:"  + active_link_link);
		
		if( active_link_link > 16 && active_link_link < 32 ){
			new_left = $("#topmenu_panel").width();
			$("#topmenu_panel_pos").css('left', '-' + new_left + 'px' );
		}
		else if( active_link_link > 32 ){
			new_left = (2 * $("#topmenu_panel").width());
			$("#topmenu_panel_pos").css('left', '-' + new_left + 'px' );
		}
		
		// save index in cookie
		createCookie(cookie_name,active_link_link,7);
		
		
		// topmenu switch links
		$("A.topnav_linknext").click(function(){
			
			topmenu_slide_next();
			return false;
			
		});
		
		
		$("A.topnav_prevlink").click(function(){

			topmenu_slide_prev();
			return false;
			
		});
		
		
		if( $("UL#img_switch_list LI A").length ){
			
			if( !$(".non_resizable_panel").length  ){
				
				// activate first
				if( $("UL#img_switch_list LI A:not(#img_prev , #img_next).active").length == 0 ){ 
					$("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(0).addClass("active"); 
					$("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(0).addClass("cached");
					if( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(0).hasClass("white_bg") ){ $("BODY").addClass('white_bg');  }
				}
				
				// click event for switch links
				$("UL#img_switch_list LI A:not(#img_prev , #img_next)").click(function(){
				
					img_switch_list_link_click( $(this) );
				
					//if( $(this).attr('class') == "" ){
					/*if( !$(this).hasClass('active') ){
				
						// white BG ?
						$("BODY").removeClass('white_bg');
						if( $(this).hasClass('white_bg') ){ $("BODY").addClass('white_bg'); }
				
						// hide ballon
						hide_ballon();
						
						// remove active from all
						$("UL#img_switch_list LI A").removeClass("active");
						
						// show preloader
						ie_cache = "";
						if( !$(this).hasClass('cached') ){ show_preloader(); }
						if( $.browser.browser() == "Internet Explorer" ){ 
							show_preloader();
							ie_cache = "?random=" + Math.random()*99999; 
						}
						
						// load next img
						$('<img />')
						    .attr('src', $(this).attr('href') + ie_cache)
							.attr('width', '1000')
							.attr('id', 'work_img')
						    .load(function(){
						    	
								// remove current img
								$("#site_panel IMG#work_img").remove();
						   						   		
						   		// add img to site panel
								$("#site_panel").append($(this));
								
								// set img width to 100%
								$("#site_panel IMG").width('100%');
								
								// hide preloader
								hide_preloader();
								
								// show ballon ?
								show_ballon_for_active_link();	
								   			       
						    });
						    
								
						// add cached class
						$(this).addClass("cached");
						
						// mark this link active
						$(this).addClass("active");		
		
						
					}*/
				
	
					return false;
					
				});
				
				
				
				// prev, next arrow
				$("UL#img_switch_list LI A#img_prev").click(function(){
				
					// if can go to prev
					var active_link_index	= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").index($("UL#img_switch_list LI A:not(#img_prev , #img_next).active"));
					
					if( active_link_index ){
						img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(active_link_index-1) );
					}
				
					return false;
					
				});
				$("UL#img_switch_list LI A#img_next").click(function(){
				
					// if can go to next
					var num_of_links 		= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").length;
					var active_link_index	= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").index($("UL#img_switch_list LI A:not(#img_prev , #img_next).active"));
					active_link_index++;
					
					if( active_link_index < num_of_links  ){
						img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(active_link_index) );
					}
				
					return false;
					
				});
				
				
				
				// over img BIG ARROWS - create
				if( !($("#project_arrow_left").length && $("#project_arrow_right").length) ){
					$("BODY").append('<a href="#" id="project_arrow_left"></a>');
					$("BODY").append('<a href="#" id="project_arrow_right"></a>');
				} 
				
				// over img BIG ARROWS - bind click
				if( $("#project_arrow_left").length ){
					$("#project_arrow_left").click(function(){
					
						// if can go to prev
						var active_link_index	= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").index($("UL#img_switch_list LI A:not(#img_prev , #img_next).active"));
						
						if( active_link_index ){
							img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(active_link_index-1) );
						}
						else {
							img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq($("UL#img_switch_list LI A:not(#img_prev , #img_next)").length - 1) );
						}
					
						return false;
						
					});
				}
				
				if( $("#project_arrow_right").length ){
					$("#project_arrow_right").click(function(){
					
						// if can go to next
						var num_of_links 		= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").length;
						var active_link_index	= $("UL#img_switch_list LI A:not(#img_prev , #img_next)").index($("UL#img_switch_list LI A:not(#img_prev , #img_next).active"));
						active_link_index++;
						
						if( active_link_index < num_of_links  ){
							img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(active_link_index) );
						}
						else {
							
							img_switch_list_link_click( $("UL#img_switch_list LI A:not(#img_prev , #img_next)").eq(0) );
							
						}
					
						return false;
						
					});
				}
				
				
				// check ballon for .active link
				if( $("UL#img_switch_list LI A.active").length == 1 ){
					
					// show_ballon_for_active_link
					show_ballon_for_active_link();
					
				}
							
				
			}
			else {
				
				var overlay_img = $("#img_switch_list LI A:first").attr('rel');	
				img_dims 		= $("#img_switch_list LI A:first").attr('title');
				img_dims1 		= img_dims.split("-");
	
				// append BODY with over img	
				//if( $("#start_link").length ){ $('#start_link').html('<img src="'+overlay_img+'" width="'+img_dims1[0]+'" height="'+img_dims1[1]+'" alt="" title="" id="over_img">'); } 
				//else { $('BODY').append('<img src="'+overlay_img+'" width="'+img_dims1[0]+'" height="'+img_dims1[1]+'" alt="" title="" id="over_img" style="cursor: auto;">'); }	

				$('BODY').append('<img src="'+overlay_img+'" width="'+img_dims1[0]+'" height="'+img_dims1[1]+'" alt="" title="" id="over_img" style="cursor: auto;">'); 

				/// link on img
				if( $(".intro").length ){
					$('#over_img').wrap('<a id="wrap_link"></a>');
					$("#wrap_link").attr('href',$(".hidden").attr('href'));
					$('#over_img').attr('style', '');

				}

				// remove work img
				$("#img_switch_list").remove();
				$("#work_img").remove();
				$("#img_ratio").remove();
				
				$("#site_panel").height($("#over_img").height());
				
				// contact link
				/*if( $(".small_img_link").length ){
					
					// add small contact link 
					$("#site_panel").after($(".small_img_link"));
					
					$("#site_panel").height($("#over_img").height() + $(".small_img_link").height() );
					$(".small_img_link").css('margin-left', $("#over_img").css('left'));
				
					
				}*/

				
				
			}
	
			
			

			
		}
		
		// pre page - adjust height
		if( $(".pre_page").length ){
		
			// window resize event
			$(window).resize(function() {
				  
				pre_page_adjust_height();
				
			  
			});
			
			pp_timeout = setTimeout("pre_page_adjust_height();", 200);
			
		}
		
		
		// window resize event for project page
		if( $(".resizable_panel").length ){
			
			if( $("#site_panel IMG").length ){
		
				$("#site_panel IMG")
				.attr( 'src' , $("#site_panel IMG").attr('src') )
				.load(function(){
					
					
					// window resize event
					$(window).resize(function() {
						  
						adjust_panel();
						
						
						// prev next arrows
						autoheight_arrows();
					  
					});
					
					r_timeout = setTimeout("adjust_panel();", 200);					
					
					
				});
				
				

				
				//adjust_panel();					
				
			}
			

		}
		

		// hide controls
		if( $(".hide_controls").length ){
			
			//$("#img_switch_list").remove();
			
			img_dims1 	= $("#img_switch_list LI A:first").attr('title');
			img_dims1 	= img_dims1.split("-");
			
			ap_img		= '<img src="'+$("#img_switch_list LI A:first").attr('rel')+'" width="'+img_dims1[0]+'" height="'+img_dims1[1]+'" alt="" title="">';
			// alert( ap_img );
			
			$("#start_link").html( ap_img );
			/*.append( ap_img )
			.load(function(){
				alert($(this));
			});*/
			
			$("#img_switch_list").remove();
			
		}

		
	});