// JavaScript Document
$(document).ready(function() {
/*------------------PNG FIX -----------------------------*/
 $(document).pngFix(); 
 /*------------------SUPPORT HOVER-----------------------------*/
$(".support_link").hover(
   function(){
   	var logo_name="img/ui/support_logo/rollover/"+$(this).attr("id")+".jpg";
	$(this).attr({src:logo_name});
	},
	function(){
	var logo_name="img/ui/support_logo/"+$(this).attr("id")+".jpg";
	$(this).attr({src:logo_name});
	});
/*------------------PROTOTYPE LINKS HOVER-----------------------------*/
var color;	
$(".link").add(".link_number").add(".link_next").add(".link_prev").hover(function(){
	color=$(this).children(".link_m").css("color");
	$(this).children(".link_m").css({'color':'#0077ff','cursor':'pointer'});
	},
	function(){
	 $(this).children(".link_m").css({'color':color});
	});
$(".section_title1").add(".section_title2").add(".section_title3").each(function(){
																				   var all_text=$(this).html();
																				   $(this).html(all_text.replace(/([A-Z])/g,'<span>$1</span>'));
																					
																				   });
/*------------------PROTOTYPE IMAGES-----------------------------*/
$(".proto_photo_wrapper").add(".proto_video_wrapper").find("img").addClass("thumb_img").attr({width:"20", height:"20"}).wrap('<div class="proto_thumb"></div>');

$(".proto_thumb").each(function(){
							$(this).attr({id:$(this).find("img").attr("alt")}).find("img");
						   $(this).append('<div class="preview"><img src="'+$(this).find("img").attr('src')+'" /></div>');
						   });
$(".preview").hide();
$(".proto_thumb").hover(function(){
				$(this).find(".preview").fadeIn(10);
				},function(){
				$(this).find(".preview").fadeOut(100,function(){$(this).hide();});
				}
				);


$(".proto_photo_wrapper").find(".proto_thumb").click(
						function(){
						var prototype_name=$(this).parent().parent().attr("id");
						var new_proto_src='../prototypes/'+prototype_name+'/low_rez/'+$(this).attr("id")+'_low.jpg';
						var new_proto_hirez='../prototypes/'+prototype_name+'/hi_rez/'+$(this).attr("id")+'_hi.jpg';
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").find("a").attr({href:new_proto_hirez});
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").show();
						$("#"+prototype_name+"_image").fadeOut(100,function(){
							 var img = new Image();
							 $(img).load(function(){
										 $("#"+prototype_name+"_image").html('<img src="'+new_proto_src+'"/>').fadeIn(300);
										 }).attr('src',new_proto_src);
							});
						
						$(this).parent().find(".thumb_img").removeClass("proto_selected").addClass("thumb_img");
						$(this).find(".thumb_img").addClass("proto_selected");
													});
$(".proto_video_wrapper").find(".proto_thumb").click(
						function(){
						var prototype_name=$(this).parent().parent().attr("id");
						var new_video_src='../prototypes/'+prototype_name+'/video/'+$(this).attr("id")+'.php';
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").hide();
						$("#"+prototype_name+"_image").fadeOut(100,function(){
							 $("#"+prototype_name+"_image").load(new_video_src).fadeIn(300);
																				});
						
						$(this).parent().find(".thumb_img").removeClass("proto_selected").addClass("thumb_img");
						$(this).find(".thumb_img").addClass("proto_selected");
									});
/*------------------PROJECT IMAGES-----------------------------*/
$(".project_photo_wrapper").add(".project_video_wrapper").find("img").addClass("thumb_img").attr({width:"20", height:"20"}).wrap('<div class="proto_thumb"></div>');

$(".proto_thumb").each(function(){
							$(this).attr({id:$(this).find("img").attr("alt")}).find("img");
						   $(this).append('<div class="preview"><img src="'+$(this).find("img").attr('src')+'" /></div>');
						   });
$(".proto_thumb").hover(function(){
				$(this).find(".preview").fadeIn(10);
				},function(){
				$(this).find(".preview").fadeOut(100,function(){$(this).hide();});
				}
				);

$(".project_photo_wrapper").find(".proto_thumb").click(
						function(){
						var prototype_name=$(this).parent().parent().attr("id");
						var new_proto_src='../projects/'+prototype_name+'/low_rez/'+$(this).attr("id")+'_low.jpg';
						var new_proto_hirez='../projects/'+prototype_name+'/hi_rez/'+$(this).attr("id")+'_hi.jpg';
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").find("a").attr({href:new_proto_hirez});
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").show();
						$("#"+prototype_name+"_image").fadeOut(100,function(){
							 var img = new Image();
							 $(img).load(function(){
										 $("#"+prototype_name+"_image").html('<img src="'+new_proto_src+'"/>').fadeIn(300);
										 }).attr('src',new_proto_src);
							});
						
						$(this).parent().find(".thumb_img").removeClass("proto_selected").addClass("thumb_img");
						$(this).find(".thumb_img").addClass("proto_selected");
													});
$(".project_video_wrapper").find(".proto_thumb").click(
						function(){
						var prototype_name=$(this).parent().parent().attr("id");
						var new_video_src='../projects/'+prototype_name+'/video/'+$(this).attr("id")+'.php';
						$("#"+prototype_name+"_image").parent().find(".prototype_hi_rez").hide();
						$("#"+prototype_name+"_image").fadeOut(100,function(){
							 $("#"+prototype_name+"_image").load(new_video_src).fadeIn(300);
																				});
						
						$(this).parent().find(".thumb_img").removeClass("proto_selected").addClass("thumb_img");
						$(this).find(".thumb_img").addClass("proto_selected");
									});



/*------------------PHOTO -----------------------------*/
$(".thumb_wrapper").find("img").addClass("thumb_img").attr({width:"20", height:"20"}).wrap('<div class="thumb"></div>');
$(".thumb").each(function(){
						   $(this).attr({id:$(this).find("img").attr("alt")}).find("img").fadeTo(1000,.9);
						   $(this).append('<div class="preview"><img src="../photos/thumb/'+$(this).attr("id")+'_thumb.jpg" /></div>');
						   });
$(".preview").hide();
$(".thumb").hover(function(){
				$(this).find(".preview").fadeIn(10);
				},function(){
				$(this).find(".preview").fadeOut(100,function(){$(this).hide();});
				}
				);

$.fn.loaded_photo = function(src, f){
var i = new Image();
var t = $(this);
$(i).load(function(){$(".big_photo").html($(this));f();}).attr('src', src);
};

$(".big_photo").hide().loaded_photo('../photos/low_rez/'+document.location.hash.replace("#","")+'_low.jpg',function(){
						$("#menu").find("div").find("div").css({"background":"transparent"}).fadeTo(2000,.7);
						$("#menu").find("div").hover(function(){
															$(this).find(".link_r").fadeTo(100,1).css({"backgroundImage":"url(img/ui/link/link_r.png)"});
															$(this).find(".link_l").fadeTo(100,1).css({"backgroundImage":"url(img/ui/link/link_l.png)"});
															$(this).find(".link_m").fadeTo(100,1).css({"backgroundImage":"url(img/ui/link/link_m.png)"});
																			  },function(){
															 $(this).find("div").fadeTo(100,.7).css({"background":"transparent"});
																			  });
						
						
						var window_y=parseFloat($(window).height());
						var window_x=parseFloat($(window).width());
						var window_proportion=parseFloat(window_x/window_y);
						$(".big_photo").css({"width":window_x+'px',"height":window_y+'px'});
						if(window_proportion>=1.25){
						$(".big_photo").find("img").css({"width":window_x,"height":window_x/1.25,"left":"0px"});
						}
						else{
						$(".big_photo").find("img").css({"heigh":window_y,"width":window_y*1.25,"left":"-"+(window_y*1.25-window_x)/2+"px"});	
						}																						 
						$(".big_photo").fadeIn(500,function(){$("body").css({backgroundColor:"#000000"});});
						$("#print_quality").find("a").attr({href:'../photos/hi_rez/'+document.location.hash.replace("#","")+'_hi.jpg'});
						
						var this_photo_name=document.location.hash;			  
						$(this_photo_name).find(".thumb_img").css({border:"1px solid #ffffff"});
						var this_photo_nohash=this_photo_name.replace("#","");
						var this_photo_title=this_photo_nohash.replace("_"," ");
						$("#photo_description_name").html(this_photo_title);
						var description_url="photo_description.php?photo_name="+this_photo_nohash;
						$("#photo_description_text").load(description_url);
						
						
												
						
																												 });


$(window).resize(function(){
				 	var window_y=parseFloat($(window).height());
					var window_x=parseFloat($(window).width());
					var window_proportion=parseFloat(window_x/window_y);
					$(".big_photo").css({"width":window_x,"height":window_y});
					if(window_proportion>=1.25){
					$(".big_photo").find("img").css({"width":window_x,"height":window_x/1.25,"left":"0px"});
					}
					else{
					$(".big_photo").find("img").css({"height":window_y,"width":window_y*1.25,"left":"-"+(window_y*1.25-window_x)/2+"px"});	
					}
				 });
						
$(".thumb").click(function(){
						var new_photo_src='../photos/low_rez/'+$(this).attr("id")+'_low.jpg';
						var new_photo_name=$(this).attr("id");
						var width=$(".big_photo").find("img").attr("width");
						var height=$(".big_photo").find("img").attr("height");
						$(".big_photo").fadeOut(100,function(){
															 $(this).loaded_photo(new_photo_src,function(){
																						$(".big_photo").find("img").attr({width:width, height:height});
																						$(".big_photo").fadeIn(300);
																						 });
															 });
						document.location.hash=$(this).attr("id");
						$("#print_quality").find("a").attr({href:'../photos/hi_rez/'+new_photo_name+'_hi.jpg'});
						$(".thumb_img").css({border:"none"});
						$(this).find(".thumb_img").css({border:"1px solid #ffffff"});
						var this_photo_title=new_photo_name.replace("_"," ");
						$("#photo_description_name").html(this_photo_title);
						var description_url="photo_description.php?photo_name="+new_photo_name;
						$("#photo_description_text").load(description_url);
						});
$("#next_photo").click(function(){
				var  $current_photo=$(".thumb_wrapper").find("#"+document.location.hash.replace("#",""));
				var  $next_photo=$current_photo.next();
				if($next_photo.attr("id")==undefined){
					$next_photo=$(".thumb_wrapper").find(".thumb:first");
					}
				var new_photo_src='../photos/low_rez/'+$($next_photo).attr("id")+'_low.jpg';
				var new_photo_name=$($next_photo).attr("id");
				var width=$(".big_photo").find("img").attr("width");
				var height=$(".big_photo").find("img").attr("height");
						$(".big_photo").fadeOut(300,function(){
															 $(this).loaded_photo(new_photo_src,function(){
																						$(".big_photo").find("img").attr({width:width, height:height});
																						$(".big_photo").fadeIn(300);
																						 });
															 });
						document.location.hash=$($next_photo).attr("id");
						$("#print_quality").find("a").attr({href:'../photos/hi_rez/'+new_photo_name+'_hi.jpg'});
						$(".thumb_img").css({border:"none"});
						$($next_photo).find(".thumb_img").css({border:"1px solid #ffffff"});
						var this_photo_title=new_photo_name.replace("_"," ");
						$("#photo_description_name").html(this_photo_title);
						var description_url="photo_description.php?photo_name="+new_photo_name;
						$("#photo_description_text").load(description_url);
								});
$("#prev_photo").click(function(){
				var  $current_photo=$(".thumb_wrapper").find("#"+document.location.hash.replace("#",""));
				var  $prev_photo=$current_photo.prev();
				
				if($prev_photo.attr("id")==undefined){
					$prev_photo=$(".thumb_wrapper").find(".thumb:last");
					}
				var new_photo_src='../photos/low_rez/'+$($prev_photo).attr("id")+'_low.jpg';
				var new_photo_name=$($prev_photo).attr("id");
				var width=$(".big_photo").find("img").attr("width");
				var height=$(".big_photo").find("img").attr("height");
						$(".big_photo").fadeOut(300,function(){
															 $(this).loaded_photo(new_photo_src,function(){
																						$(".big_photo").find("img").attr({width:width, height:height});
																						$(".big_photo").fadeIn(300);
																						 });
															 });
						document.location.hash=$($prev_photo).attr("id");
						$("#print_quality").find("a").attr({href:'../photos/hi_rez/'+new_photo_name+'_hi.jpg'});
						$(".thumb_img").css({border:"none"});
						$($prev_photo).find(".thumb_img").css({border:"1px solid #ffffff"});
						var this_photo_title=new_photo_name.replace("_"," ");
						$("#photo_description_name").html(this_photo_title);
						var description_url="photo_description.php?photo_name="+new_photo_name;
						$("#photo_description_text").load(description_url);
								});
$("#photo_description").add(".off").hide();
$("#description_button").click(function(){
						if($("#photo_description").css("display")=="none"){
							$("#photo_description").fadeIn(500);
							$(".on").hide();
							$(".off").show();
							}
						else{
							$("#photo_description").fadeOut(500);
							$(".on").show();
							$(".off").hide();
							}
						
										});

/*------------------ TEAM -----------------------------*/

$(".section1[title='team']").hover(function(){
											$(this).find(".team_text").fadeIn(100);
											$(this).css({cursor:"pointer",zIndex:"2"});
											},function(){
											$(this).find(".team_text").fadeOut(100);
											$(this).css({cursor:"pointer",zIndex:"1"});
											});

});

