
$(document).ready(function(){
	
	
	

	if(!$.browser.msie){
		
		
		
		if (!$.browser.msie){
			$('.hover_alpha_out:not(.hover_alpha_out.active)').hover(function(){$(this).stop().animate({opacity : .5}, 150)}, function(){$(this).stop().animate({opacity : 1}, 150)});
			$('.hover_alpha_out_75').hover(function(){$(this).stop().animate({opacity : .75}, 150)}, function(){$(this).stop().animate({opacity : 1}, 150)});
			$('.hover_alpha_in').hover(function(){$(this).stop().animate({opacity : 1}, 150)}, function(){$(this).stop().animate({opacity : .5}, 150)});
			
		}
		
		
		//MENU (NAVI_DIV);
		
		$('#navi_div .menu_cnt .arrow').mouseover(function(){
			$('#navi_div .menu_cnt .link_list').stop().animate({width : 330, opacity : 1}, 500, function(){
					$('#navi_div').addClass('open');
				});
		});
		
		
		$('#navi_div .menu_cnt .arrow').click(function(){
			
			$('#navi_div .menu_label').unbind('mouseover');
			
			$('#navi_div .menu_cnt .link_list').stop().animate({width : 1, opacity : 0}, 500, function(){
				$('#navi_div').removeClass('open');
				setMenuLabelMouseOverEvent();
			});
			
			
			
		});
		
		var setMenuLabelMouseOverEvent = function(){
			$('#navi_div .menu_label').mouseover(function(){
				$('#navi_div .menu_cnt .arrow').mouseover();	
			});
		}
			
		
		setMenuLabelMouseOverEvent();
		$('#navi_div .menu_label').click(function(){$('#navi_div .menu_cnt .arrow').click();});
		
		
		//HOME
		if("home" == _action){
			var img2load;
			
			$('#cnt_main').css({'display':'none'});
			
			//img2load for slideshow
			switch(_bgmId){
				
				case 1:
				img2load = 'resource/img/content/home/83812897.jpg';
				break;
				
				case 2:
				img2load = 'resource/img/content/home/83743479.jpg';
				break;
				
			}
			
			//preloadimage
			function loadImage(img_src){
				var img = new Image();
				$(img).attr('src',img_src)
				$(img).load(function(){
					$(this).remove();
					loadBGSlideShow();
				});
			}
			
			function loadBGSlideShow(){
				
				
				
				//animate
				var waiting_time_ani = 500;
				var ani_duration = 1000;
				var wt_index = 0;
				

				var getWaitingTime = function(){
					var new_waiting_time = waiting_time_ani * wt_index;
					wt_index += 1;
					return new_waiting_time;
				}
				
				//flying_text 
				$('#flying_txt').click(function(){sortedIntroClick();});
				//intro animation                            
				
				$.each( $('span, h2 ', "#flying_txt"), function(i, txt_line){
					$(this).delay(waiting_time_ani * i).animate({marginLeft : 0 + "px"},ani_duration );
				});
				
				//loadBGSlideShow();
				setTimeout(function(){
					$('#flying_txt').animate({marginLeft : ($(window).width())}, 500, function(){
							$('body *').fadeOut(500, function(){
							window.location.href = "5-0-Projekte.html";
						});
					});
					
					
				}, stay_on_page_duration);
				
				
				
				jQuery(function($){
						$.supersized({
						
							//Functionality
							slideshow               :   1,		//Slideshow on/off
							autoplay				:	0,		//Slideshow starts playing automatically
							start_slide             :   _bgmId,		//Start slide (0 is random)
							random					: 	0,		//Randomize slide order (Ignores start slide)
							slide_interval          :   5000,	//Length between transitions
							transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
							transition_speed		:	1500,	//Speed of transition
							new_window				:	0,		//Image links open in new window/tab
							pause_hover             :   0,		//Pause slideshow on hover
							keyboard_nav            :   0,		//Keyboard navigation on/off
							performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
							image_protect			:	0,		//Disables image dragging and right click with Javascript
							image_path				:	'', //Default image path
		
							//Size & Position
							min_width		        :   0,		//Min width allowed (in pixels)
							min_height		        :   0,		//Min height allowed (in pixels)
							vertical_center         :   1,		//Vertically center background
							horizontal_center       :   1,		//Horizontally center background
							fit_portrait         	:   0,		//Portrait images will not exceed browser height
							fit_landscape			:   0,		//Landscape images will not exceed browser width
							
							//Components
							navigation              :   1,		//Slideshow controls on/off
							thumbnail_navigation    :   0,		//Thumbnail navigation
							slide_counter           :   0,		//Display slide numbers
							slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
							slides 					:  	[		//Slideshow Images
																{image : img2load, title : '', url : ''},  
																{image : img2load, title : '', url : ''}
														]
														
						}); 
					});
					
				}
				
				var stay_on_page_duration = 5000;
				
				switch(_bgmId){
					case 1:
					stay_on_page_duration = 5000;
					break;
					
					case 2:
					stay_on_page_duration = 6000;
					break;
				}
				
				
				
				loadImage(img2load);
	
				
			
			
		}
		
		
		//GALLERY
		if("gallery" == _action){
			
			var fb_margin = 150;
			var current_fancybox_arr;
			var current_fancybox_index;
			var fancybox_open = false;
			var infoBox_open = false;
			var info_box_duration = 250;
			var fb_controls_duration = 500;
			var window_resize_interval;
			var window_resize_interval2;
			var fb_img_id_current = "";
			var btn_fb_2_info_out = false;
			var btn_fb_2_mouseOver = false;
			
			
			
			
			//mouse_info
			var mouse_loop;
			var mouseX = 0, mouseY = 0;
			// cache the selector
			var follower = $("#fb_tooltip");
			var xp = $(window).width() / 2;
			var yp = $(window).height() / 2;
			//mouse_info -- end
			
			
			
			
			//function on windowResize
			var onWindowResize = function(){
				
							
				clearTimeout(window_resize_interval);
				clearTimeout(window_resize_interval2);
				
				if(fancybox_open){
					
					//var w_h_offset = $(window).height() - $('#fancybox-img').height() - (fb_margin * 2);
					window_resize_interval = setTimeout(function(){
						
						hide_info_box();
						show_info_line(false);
						$(current_fancybox_arr[current_fancybox_index]).click();
						clearTimeout(window_resize_interval);
						
						
					}, 500);
					
					//controls if a lot of white space for the fancybox 
					//image and if the image should be clicked again
					
					
				}
				$('#portfolio_ov ul#client_list ul.thumb').width($(window).width() - 300);
			}
			
			
			//##portfolio_ov click feat ################################################
			$('#client_list .item_client .arrow_enlarge').toggle(function(){
					$(this).parent().find('li.feat_0').addClass("now_feat").animate({width : 132}, 300, function(){
							$(this).parent().find('li.arrow_enlarge').addClass('enlarged');
						});	
				}, function(){
					$(this).parent().find('li.now_feat').animate({width : 0}, 300, function(){
						$(this).parent().find('li.enlarged').removeClass('enlarged');
						$(this).removeClass('now_feat');
					});	
					
			});	
			
			//visibility
			$.each($('#client_list .item_client .arrow_enlarge'), function(){
				$(this).css({'display' : (($(this).parent().find('li.feat_0').length > 0) ? 'block' : 'none' )});
			});
			
			
			
			
			//##fancybox_onInit ################################################
			
			var fancybox_onInit = function(obj_arr, obj_index, opts){
				
				var current_obj = obj_arr[obj_index];
				var current_obj_data = $(current_obj).metadata();
				
				//set values
				current_fancybox_arr = obj_arr;
				current_fancybox_index = obj_index;
				
				// real init
				if(!fancybox_open){
					
					$('#portfolio_ov').animate({'opacity':0});
					$('#btn_fb_1').css({display : 'block'}).animate({'left':0});
					$('#btn_fb_2').css({display : 'block'}).animate({'right':0});
					$('#btn_ov').css({display : 'block'}).animate({'bottom':0});
				}
				
				
				
				//sets fancybox busy variable 
				fancybox_open = true;
				$('body').addClass('fancybox_is_open');
				
				
			}
			
			
			//##fancybox_next_btn_click ################################################
			
			var fancybox_next_btn_click = function(direction){
				
				var wait_for_infobox_to_close;
				
				//if info box is open hide();
				if(infoBox_open){
					wait_for_infobox_to_close = true;
					hide_info_box();
				}
				
				//direction // "next" ||"prev"
				if(direction == "undefined"){
					direction == "next";
				}
				
				if(wait_for_infobox_to_close){
					var ibto = setTimeout(function(){
						if(direction == "next") { 
							$.fancybox.next();
						}else if(direction == "prev"){ 
							$.fancybox.prev();
						}
						clearTimeout(ibto);
					}, info_box_duration);
				}
				else{
					if(direction == "next") { 
							$.fancybox.next();
						}else if(direction == "prev"){ 
							$.fancybox.prev();
						}
		
				}
				
				//info_line
				show_info_line(false);
				
				//unset event listener
				$('#fancybox-img').unbind('click');
				$('#fancybox-img').unbind('mousemove');
			}
			
			
			
			
			//##fancybox_onExit ################################################
			var fancybox_onExit = function(){
				
				var wait_for_infobox_to_close;
				
				
				//prüfen ob im sorted modus
				if(_sorted){
					window.location.href = "5-0-Projekte.html";
				}else{
					//if info box is open hide();
					if(infoBox_open){
						wait_for_infobox_to_close = true;
						hide_info_box();
						fb_controls_animation_out();
					}else{
						fb_controls_animation_out();
					}
					
					//unset event listener
					$('#fancybox-img').unbind('click');
					$('#fancybox-img').unbind('mousemove');
					
					//remove fb_tooltip
					$('#fb_tooltip').hide();
					
					//unsets fancybox busy variable
					fancybox_open = false;
					$('body').removeClass('fancybox_is_open');
					
					
					//unsetes fb_img_id_current
					fb_img_id_current = "";
				}
				
				onWindowResize();
					
			}
			
			
			
			//##fb_controls_animation_out ################################################
			
			var fb_controls_animation_out = function(){
				
				$('#btn_fb_1').animate({'left':-44}, fb_controls_duration, function(){$(this).css({display : 'none'});});
				$('#btn_fb_2').animate({'right':-44}, fb_controls_duration, function(){$(this).css({display : 'none'});});
				$('#btn_ov').animate({'bottom':-45}, fb_controls_duration, function(){$(this).css({display : 'none'});});
				fb_ov_show();
				
				//show the overview
				var show_ov_timeout = setTimeout(function(){
					$.fancybox.close();
					//info_line
					show_info_line(false);
					clearTimeout(show_ov_timeout);
				}, fb_controls_duration);
				
				
				//hide active sort
				$('.headline_digital, .headline_print, li, a', '#sort_control_div').removeClass("current");
			}
			
			
			
			//##fb_ov_show ################################################
			
			var fb_ov_show = function(){
				$('#portfolio_ov').animate({'opacity':1}, 2000);
			}
			
			
			
			
			//##fancybox_onComplete ################################################
			
			var fancybox_onComplete = function(){
				
				
				
				//unset event listener
				$('#fancybox-img').unbind('click');
				$('#fancybox-img').unbind('mousemove');
				$('#fancybox-img').unbind('mouseout');
				
				//set event listener
				$('#fancybox-img, #fb_tooltip').click(function(){
					if(!infoBox_open){
						show_info_box();
					}else{
						hide_info_box();
					}
				});
				
				//info_box btn_hide click event
				$('#fb_info_box').click(function(){
					if(!infoBox_open){
							
						}else{
							hide_info_box();
						}
					}	
				);
				$('#fb_info_box .link').click(function(){
					
					setTimeout(function(){
						if(!infoBox_open){
							
						}else{
							hide_info_box();
						}
						
					}, 500);
				
				});
				
				
				var img_info_data_current = fancybox_getInfo(current_fancybox_index);
				var img_info_data_next = fancybox_getInfo(fb_arr_pos_contr("next"));
				//info_line
				$('#fb_info_line').text(img_info_data_current.client_name + " // " + img_info_data_current.project_name + " // " + img_info_data_current.img_label);
				
				$('#fb_info_line').css({marginTop : function(){
					
					if(img_info_data_current.img_media_type == 'img'){
						return $('#fancybox-img').height() + "px";
					}else if(img_info_data_current.img_media_type == 'swf'){
						return img_info_data_current.img_media_height + "px";
					}
					
					
				} });
				show_info_line(true);
				
				//txt for txt_mouseOver
				$('#fb_tooltip').html(img_info_data_current.project_name + " // " + img_info_data_current.img_label + "<br/>F&uuml;r mehr Informationen bitte klicken");
				
				//txt for btn_fb_2_info
				$("#btn_fb_2_info").css({display:'block'});
				$('#btn_fb_2_info .output').html("NEXT: " + img_info_data_next.client_name + "<br/>" + img_info_data_next.project_name + " // " + img_info_data_next.img_label);
				$("#btn_fb_2_info").css({right:($("#btn_fb_2_info").width() * - 1)});
				
				var jump_type = getJumpType("next");
				if(jump_type == "client" || jump_type == "project"){
					$("#btn_fb_2_info").addClass('new_project');
				}else{
					$("#btn_fb_2_info").removeClass('new_project');
				}
				
				
				
					//check if mouse is still over btn
					if(btn_fb_2_mouseOver) $("#btn_fb_2_info").stop().animate({right : 45}, 500, function(){btn_fb_2_info_out = true});
					
				
				//alert("$('#btn_fb_2_info .output') = " + $('#btn_fb_2_info .output').width());
				
				//info_mouse
				$("#fancybox-img, #fb_tooltip").mousemove(function(e){
					if(!infoBox_open){
						$("#fb_tooltip").show();
					}
					else{
						$("#fb_tooltip").hide();	
					}
				});
				
				$("#fancybox-img").mouseout(function(e){
					$("#fb_tooltip").hide();
				});
				
				if(mouse_loop) clearTimeout(mouse_loop);
				mouse_loop = setInterval(function(){
					if(fancybox_open){
						// change 12 to alter damping, higher is slower
						var speed = 9;
						xp += (( mouseX - xp) / speed) + 4 ;
						yp += ((mouseY - yp) / speed) - 1;
						//xp = mouseX + 30; 
						//yp = mouseY - 15; 
						follower.css({left:xp, top:yp});
						
						
					}
						
					
				}, 30);
				
				//info_mouse // end
				$('#fb_tooltip').click(function(){
					//alert("tooltip");
					$('#fancybox-img').click();				
				});
				
				
				//set fb_img_id_current
				fb_img_id_current = img_info_data_current.unique_id;
				//$.log('fb_img_id_current = ' + img_info_data_current.unique_id);
				
				//set current sort_category
				//sort_control_div
				var img_pro_type = parseFloat(img_info_data_current.project_type);			
				$('.headline_digital, .headline_print, li, a', '#sort_control_div').removeClass("current");
				switch(img_pro_type){
						
					case 1:
					case 2:
					case 3:
					case 4:
					case 5:				
					$('#sort_control_div .headline_digital').addClass("current");
					break;
					
					case 6:
					case 7:
					case 8:
					case 9:
					case 10:				
					$('#sort_control_div .headline_print').addClass("current");
					break;
					
				}
				
				
				
				
				$('li.sort_btn_' + img_pro_type + ' a' , '#sort_control_div ul').addClass('current');
				
				//show sort
				$('#sort_control_div').fadeIn();
			}
			
			
			//##fancybox_array_pos_controller ################################################
			//direction("next" / "prev")
			var fb_arr_pos_contr = function(direction){
				var index = 0;
				
				
				
				// the last index
				if(current_fancybox_index == (current_fancybox_arr.length - 1)){
					if(direction == "prev"){
						index = current_fancybox_index - 2;
					}else if(direction == "next"){
						index = 0;
					}
				}
				//the first index (0)
				else if(current_fancybox_index == 0){
					if(direction == "prev"){
						index = current_fancybox_arr.length - 1;
					}else if(direction == "next"){
						index = 1;
					}
				}
				
				else{
					if(direction == "prev"){
						index = current_fancybox_index - 1;
					}else if(direction == "next"){
						index = current_fancybox_index + 1;
					}
				}
				
				return index;
			}
			
			
			
			
			//##fancybox_getInfo ################################################
			
			var fancybox_getInfo = function(index){
				var obj = $(current_fancybox_arr)[index];
				var data = $(obj).metadata();
				return data;
			}
			
			
			
			
			
			//##show_info_box ################################################
	
			var show_info_box = function(){
				var contentHeight = 0;
				
				$('#fancybox-img').addClass('info_shown');
							
				//hide info_line
				show_info_line(false);
				
				var img_info_data = fancybox_getInfo(current_fancybox_index);
				
				$('#fb_info_box .box_cnt .label').html(img_info_data.client_name + " // " + img_info_data.project_name + " // " + img_info_data.img_label);
				$('#fb_info_box .box_cnt .desc').html(img_info_data.project_desc);
				
					if(img_info_data.project_link != ""){
						$('#fb_info_box .box_cnt .link').removeClass('active_0');
						$('#fb_info_box .box_cnt .link').html('<a target="_blank" href="http://' + img_info_data.project_link + '">' + img_info_data.project_link + '</a>');	
					}else{
						$('#fb_info_box .box_cnt .link').addClass('active_0');
					}
					
				
				
				$('#fb_info_box .box_cnt').width($('#fancybox-img').width() - 50);
				contentHeight = $('#fb_info_box .box_cnt').height() + (parseInt($('#fb_info_box .box_cnt').css('paddingTop'), 10) + parseInt($('#fb_info_box .box_cnt').css('paddingBottom'), 10) + 20);
				
				$('#fb_info_box').width($('#fancybox-img').width());
				$('#fb_info_box').css({opacity : 1, marginTop : $('#fancybox-img').height(), height : 0});
				
				//infobox btn close position
				$('#fb_info_box .btn_close_info_box').css({marginLeft : ($('#fancybox-img').width() - $('#fb_info_box .btn_close_info_box').width())});	
					
				$('#fancybox-img').stop().animate({opacity : .5}, info_box_duration)
				$('#fb_info_box').stop().animate({height : contentHeight, opacity : 1, marginTop : $('#fancybox-img').height() - contentHeight + 1 }, info_box_duration);
				
				
				infoBox_open = true;
		
			}
			
			
			
			
			
			//##hide_info_box ################################################
							
			var hide_info_box = function(){
				$('#fancybox-img').removeClass('info_shown');
				$('#fancybox-img').stop().animate({opacity : 1}, info_box_duration, function(){
					//background
					$('#fancybox-content').removeClass('white');
				})
				$('#fb_info_box').stop().animate({height : 0, opacity : 0, marginTop : $('#fancybox-img').height()}, info_box_duration);
				infoBox_open = false;
				
				//show info_line
				show_info_line(true);
			}
			
			
			
			//##hide_info_box ################################################
			
			var info_line_is_shown = false;
			var show_info_line = function(show){
				if(show && !info_line_is_shown){
					$('#fb_info_line').stop().animate({opacity : 1}, 150);
					info_line_is_shown = true;
				}else if(!show && info_line_is_shown){
					$('#fb_info_line').stop().animate({opacity : 0}, 150);
					info_line_is_shown = false;
				}
			}
			
			
			
			//##hide_info_box ################################################
			
			var onBtnHideInfoBoxClick = function(){
				//show info_line
				show_info_line(true);
			
				hide_info_box();
			}
			
			
			
			
			//##hide_info_box ################################################
			
			var showCustomCursor = function(){
				$('#test-area').mouseout(function(){
				   $('#mycursor').stop().hide();
					   return 	false;
				  });
				  $('#test-area').mouseenter(function(){
					   $('#mycursor').stop().show();
					   return false;
				  });
				  $('#test-area').mousemove(function(e){
					   $('#mycursor').css('left', e.clientX - 20).css('top', e.clientY + 7);
			  });
			}
			
			
			
			
			
			
			//##getJumpType ################################################
			
			var getJumpType = function(direction){
				var jumpType = "img";
				var tgt_current;
				var tgt_current_data;
				var tgt_next;
				var tgt_next_data;
				
				tgt_current = current_fancybox_arr[current_fancybox_index];
				tgt_next = current_fancybox_arr[fb_arr_pos_contr(direction)];
				tgt_current_data = $(tgt_current).metadata();
				tgt_next_data = $(tgt_next).metadata();
				
					
				//check if is new client
				if(tgt_current_data.client_id != tgt_next_data.client_id){
					//$.log("other client");
					return "client"; 
				}
				else{
					//check if is new project
					if(tgt_current_data.project_id != tgt_next_data.project_id){
						//$.log("other project");
						return "project"; 
					}
					else{
						//$.log("just another img");
						return jumpType;
					}
				}
				
			}
			
				
	//##          ################################################
	//##   init   ################################################
			
			$('.fb:not(.fb.swf)').fancybox({
				'transitionIn'		:	'elastic',
				'transitionOut'		:	'fade',
				'speedIn'			:	500, 
				'speedOut'			:	200, 
				'overlayShow'		:	false,
				'padding'			:	0,
				'margin'			:	fb_margin,
				'showNavArrows'		:	false,
				'showCloseButton'	:	false,
				'enableEscapeButton':	false,
				'cyclic'			:	true,
				'onStart'			:	fancybox_onInit,
				'onComplete'		:	fancybox_onComplete,
				hideOnOverlayClick	:	true,
				'centerOnScroll'	:	true,
				scrolling			:	false
				
			});
			
			
			
			$(".fb.swf").each(function(){
				
				var fb_item_clip_id = $(this).attr("href");
				var fb_item_w = $(this).metadata().img_media_width;
				var fb_item_h = $(this).metadata().img_media_height;
				
				$(this).fancybox($.extend({
					'padding' : 0,
					'cyclic' : true,
					'overlayShow'		:	false,
					'autoScale' : false,
					'transitionIn'		:	'elastic',
					'transitionOut'		:	'fade',
					'speedIn'			:	500, 
					'speedOut'			:	200, 
					'width' 			: 	fb_item_w,
					'height' 			: 	fb_item_h,
					'type' 				: 	'swf',
					'showNavArrows'		:	false,
					'showCloseButton'	:	false,
					'enableEscapeButton':	false,
					'cyclic'			:	true,
					'onStart'			:	fancybox_onInit,
					'onComplete'		:	fancybox_onComplete,
					hideOnOverlayClick	:	true,
					'centerOnScroll'	:	true,
					scrolling			:	false,
					'swf' : {
						'wmode' : 'transparent',
						'allowfullscreen' : 'true'
					}
				}, {'href' : 'http://vimeo.com/moogaloop.swf?clip_id=' + fb_item_clip_id + '&amp;fullscreen=1' })
				);
				
			});
			
			
			
			
			
		
			
			
			
			
			
			//BG RESIZE
			/*$("body").ezBgResize({
				img     : "resource/img/layout/gallery_bg.jpg", // Relative path example.  You could also use an absolute url (http://...).
				opacity : 1, // Opacity. 1 = 100%.  This is optional.
				center  : true // Boolean (true or false). This is optional. Default is true.
			});
			*/
			
			
			
			
			var z_i = 1;
			$("ul.thumb li").hover(function() {
				$(this).css({'z-index' : z_i }); /*Add a higher z-index value so this image stays on top*/ 
				$("img", this).addClass('shadow');
				$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
					.animate({
						marginTop: '-8px', /* Set alignment back to default */
						marginLeft: '-12px',
						top: '0',
						left: '0',
						width: '157px', /* Set width back to default */
						height: '100px' /* Set height back to default */
			
					}, 100); /* this value of "200" is the speed of how fast/slow this hover animates */
					
					z_i += 1;
			
			} , function() {
				$(this).css({'z-index' : z_i}); /* Set z-index back to 0 */
				$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
					.animate({
						marginTop: '0', /* Set alignment back to default */
						marginLeft: '0',
						top: '0',
						left: '0',
						width: '132px', /* Set width back to default */
						height: '84px' /* Set height back to default */
			
					}, 100);
					
				$(this).find('img').removeClass("shadow");
				z_i += 1;
			});
			
			
			
			
			
			//set events ############################################################################################################################################
					
					
			//fancybox_control 
			$('#btn_fb_close').click(function(){
				fancybox_onExit();
			});
			
			document.onkeydown = function(e){ 
				if(fancybox_open){
				  if (e == null) { // ie 
					keycode = event.keyCode; 
				  } else { // mozilla 
					keycode = e.which;
				  } 
				  if(keycode == 27){ // escape, close box, esc 
					  fancybox_onExit();
				  } 
				}
			};
			
			//mouse
			$(document).mousemove(function(e){
				if(fancybox_open){
					mouseX = e.pageX;
					mouseY = e.pageY; 
				}
				
			});
			
			
			
			//fancybox_control 
			$('#btn_fb_2').click(function(){
				
		
				var jump_type = getJumpType("next");
				//project jump
				if(jump_type == "project"){
					$('#fancybox-wrap').stop().animate({left:$(window).width() * -1}, 250, function(){
						$('#fancybox-wrap').css({left:$(window).width() });
						fancybox_next_btn_click("next");
					});
				}
				else if(jump_type == "client"){
					$('#fancybox-wrap').stop().animate({top:$(window).height() * -1}, 250, function(){
						$('#fancybox-wrap').css({top:$(window).height() });
						fancybox_next_btn_click("next");
					});
				}
				else if(jump_type == "img"){
					fancybox_next_btn_click("next");
				}
				
				$("#btn_fb_2_info").stop().animate({right : ($("#btn_fb_2_info").width() * -1)}, 500, function(){btn_fb_2_info_out = false});
				
			});
			
			$("#btn_fb_2").hover(function(){
					$("#btn_fb_2_info").stop().animate({right : 45}, 500, function(){btn_fb_2_info_out = true});
					
				}, function(){
					$("#btn_fb_2_info").stop().animate({right : ($("#btn_fb_2_info").width() * -1)}, 500, function(){btn_fb_2_info_out = false});
			});
			
			
			//$("#btn_fb_2").mouseenter
			$("#btn_fb_2").mouseenter(function() {
				btn_fb_2_mouseOver = true;
				}).mouseleave(function() {
					btn_fb_2_mouseOver = false;
			});
			
			
			//fancybox_control 
			$('#btn_fb_1').click(function(){
				
				var jump_type = getJumpType("prev");
				//project jump
				
				if(jump_type == "project"){
					$('#fancybox-wrap').stop().animate({left:$(window).width() * 2}, 250, function(){
						$('#fancybox-wrap').css({left:$(window).width() * -1});
						fancybox_next_btn_click("prev");
					});
				}
				else if(jump_type == "client"){
					$('#fancybox-wrap').stop().animate({top:$(window).height() * 2}, 250, function(){
						$('#fancybox-wrap').css({top:$(window).height() * -1});
						fancybox_next_btn_click("prev");
					});
				}
				
				else if(jump_type == "img"){
					fancybox_next_btn_click("prev");
				}
				
				
				
			});
			
			//click sort btn
			$('#sort_control_div ul li').click(function(){
				var sort_cat = $(this).metadata().sortby;
				var fb_current_cat = (fb_img_id_current) ? parseInt($('#' + fb_img_id_current).metadata().project_type) : 0;
				
				
				//check if cat which is clicked is from type of the current image which is shown
				if(sort_cat == fb_current_cat){
					window.location.href = _current_page + "&sortby=" + sort_cat + "&fb_img_id_current=" + fb_img_id_current;
					
				}else{
					window.location.href = _current_page + "&sortby=" + sort_cat;
				}
				
				return false;
				
				
				
			});
			
			//onwindow resize
			$(window).resize(function(){
				onWindowResize();
			});
			
			$('#portfolio_ov ul#client_list ul.thumb').width($(window).width() - 300);
			
			
			var img_render = function(){
				//replace link for portfolio
				var scr_w = Math.round(screen.width * .9);
				var scr_h = Math.round(screen.height);
				var img_resize_str = String("index.php?rex_resize=" + scr_w +"w__");
				
				$('#portfolio_ov a.fb.img').each(function(){
					
					
					var href_str = $(this).attr("href");
					$(this).attr("href", img_resize_str + href_str.substring(href_str.indexOf("/") + 1));
					
				});
				
			}
			
			img_render();
			
		
		
			
			
		}
		
		
		
		
	}
	}
	
		



);

	
	
	
	
	


