var uagent = navigator.userAgent.toLowerCase();
var _touch = (uagent.search('iphone') > -1 || uagent.search('ipod') > -1 || uagent.search('ipad') > -1);
var _ipad = uagent.search('ipad') > -1;
var _iphone = uagent.search('iphone') > -1 || uagent.search('ipod') > -1;

$(function() {
 $(document).ready(function(){
	
	if (_iphone) { $("body").addClass("iphone"); }
	
	// papercraft animation
	$(".pprcrft").each(function(){
	
		var $ppr = $(this);
		if (!$ppr.hasClass("enabled")) {
			$ppr.addClass("flying enabled");
			setTimeout(function(){
				$(".pprcrft .pprst").hide();
				$(".pprcrft .ppr")
					.css({ background: "url('i/pprcrft.gif') 0 0 no-repeat", left: '149px', bottom: '-87px' })
					.animate({ left: '328px', bottom: '-10px'}, 1000, "linear", function(){ 
						$(this).css({ background: 'none' });
						$(".pprcrft .pprst").show();
						$ppr.removeClass("flying"); 
					});
			},1000);
		}
		
		$("div.intro div.intro-contact, div.ribbon.right div.label").mouseover(function(e){
			if (!$ppr.hasClass("flying")) {
				$ppr.addClass("flying");
				$(".pprcrft .pprst").hide();
				$(".pprcrft .ppr")
					.css({ background: "url('i/pprcrft.gif') 0 0 no-repeat" })
					.animate({ left: '1330px', bottom: '354px', opacity: 0 }, 6000, "linear", function(){ 
						$(this)
							.css({ left: '149px', bottom: '-87px', opacity: 1 })
							.animate({ left: '328px', bottom: '-10px'}, 1000, "linear", function(){ 
								$(this).css({ background: 'none' });
								$(".pprcrft .pprst").show();
								$ppr.removeClass("flying"); 
						});
					});
			}
		});
	});
	
	$("div.contact div.form p.input input, div.contact div.form p.text textarea").click(function(){ if ($(this).val()==$(this).attr("title")) { $(this).val(''); } }).blur(function(){ if ($(this).val()=='') { $(this).val($(this).attr("title")); } });
	$("div.contact div.form p.file-enable").click(function(){ $(this).slideUp(); $("div.contact div.form p.file").slideDown(); });
	
	$("div.contact div.form p.file").each(function(){
		var $f = $(this), $fi = $f.find("input"), $fs = $f.find("span span");
		$fi.change(function(){  
			if ($fi.val()!='') { $fs.addClass('filled'); }
			$fs.html('<b></b>' + $fi.val() );
		});
	});			
	
	$("div.block").each(function(){
							
		$.easing.def = "easeInOutQuint";
		var $b = $(this),
			id = $(this).attr("id"),
			hoverConfig = {
				timeout: 150,
				over: function(){
					var h = $(this).find("div.info").css({ 'height': 'auto' }).height();
					$(this).find("div.info").css({ 'height': '10px' }).animate({ 'height': h },1000);
					$.browser.msie ? $b.find("div.foot a").show() : $b.find("div.foot a").fadeIn();
					
					
					
				},
				out: function(){
					$b.find("div.info").animate({ 'height': '10px' },1000);  
					$.browser.msie ? $b.find("div.foot a").hide() : $b.find("div.foot a").fadeOut();
				}
			};
			
		$b.hoverIntent(hoverConfig);
		
		if ($b.find("div.show ul").length) {
			var showPics = $b.find("div.show ul li").length; 
			//$b.find("div.show ul li img").hide();
			for(var i=0;i<showPics;i++) {
				$b.find("div.foot").append('<a class=""></a>');
				$b.find("div.foot a").hide();
				if (i==0) {	
					if ($.browser.msie) {
						$b.find("div.show ul li img").eq(0).show();
						$b.find("div.foot a").eq(0).addClass("active");
						$b.find("div.show ul li").eq(0).addClass("active");
						$b.find("div.show ul li img").eq(0).css({ zIndex: 5 }).addClass("active");
						$b.find("div.show div.shadow, div.show ul, div.show ul li").height( $b.find("div.show ul li img").eq(0).height() );						
					} else {
						$b.find("div.show ul li img").eq(0).load(function() {
							$b.find("div.show ul li img").eq(0).fadeIn(function(){ $b.find("div.show ul li img").show(); });
							$b.find("div.foot a").eq(0).addClass("active");
							$b.find("div.show ul li").eq(0).addClass("active");
							$b.find("div.show ul li img").eq(0).css({ zIndex: 5 }).addClass("active");
							$b.find("div.show div.shadow, div.show ul, div.show ul li").height( $b.find("div.show ul li img").eq(0).height() );				  
						});
					}
				}
			}
	
			$b.find("div.foot a").each(function(i){
				$b.data.paging = false;
				$(this).click(function(){
					if (!$(this).hasClass("active") && $b.data.paging==false) {
						$b.data.paging = true;
						$(this).parent().find("a.active").removeClass("active");
						$(this).addClass("active");
						$b.find("div.show ul li.active").css({ zIndex: 4 }).removeClass("active");
						if ($.browser.msie) { $b.find("div.show ul li").eq(i).find("img").show(); }
						$b.find("div.show ul li").eq(i).css({ width: '1px', zIndex: 5, right: 0 }).addClass("active").animate({ width: 290 },"slow", function(){ $b.data.paging = false; });
					}
				});		
			});
		}
		
	});
	
 });
});
