(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/**
 * @author Alexander Farkas
 * v. 1.1
 */

(function($){

	if(!document.defaultView || !document.defaultView.getComputedStyle){
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
})(jQuery);

(function($) {

	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}

	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {

			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}

			start = toArray(start);
			fx.start = [start[0],start[2]];

			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];

			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}

		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

/*
$(document).ready(function(){
	
	$('#screenpos').val('0');
	
	//setTimeout()
	
	$('#screens').css( {backgroundPosition: "0 0"} );
	$('#scroll_right').bind('click',function(event){
		event.preventDefault();
		var x = $('#screenpos').val() - 199;// - 199;
		$('#screens').stop().animate({backgroundPosition:"("+x+"px 0)"}, {duration:500});
		$('#screenpos').val(x);
	});
	$('#scroll_left').bind('click',function(event){
		event.preventDefault();
		var x = parseInt($('#screenpos').val()) + 199;// - 199;
		$('#screens').stop().animate({backgroundPosition:"("+x+"px 0)"}, {duration:500});
		$('#screenpos').val(x);
	});
	
	$('#entry_0').click(function(){
		var x = $(this).val();
		if(x=="Your username"){
			$(this).val('');
		};
	});
	
	
});
*/

(function($){
	
	//$(document).ready(){
		
		var quoteArray = [
				quote = {
					text:				"This is web appery at its very&nbsp;best.",
					username:		"smb510",
					link:				"http://twitter.com/smb510/status/3350371205"
				},
				quote = {
					text:				"Hahlo 4 is awesome&nbsp;cool!",
					username:		"shimoyama",
					link:				"http://twitter.com/shimoyama/status/3375784684"
				},
				quote = {
					text:				"Really happy to see that Hahlo 4 is shaping up to be&nbsp;even more awesome day&nbsp;by&nbsp;day.",
					username:		"preshit",
					link:				"http://twitter.com/preshit/status/3326816449"
				},
				quote = {
					text:				"Hahlo is back to being my default iPhone tweet reader thanks to OAuth/oEmbed support. The less taps the&nbsp;better!",
					username:		"acetracer",
					link:				"http://twitter.com/AceTracer/status/2710673664"
				},
				quote = {
					text:				"I repeat - Hahlo is the best web client on the iPhone for&nbsp;twitter.",
					username:		"prsng",
					link:				"http://twitter.com/prsng/status/3573538121"
				},
				quote = {
					text:				"Just learned Hahlo web-based mobile twitter app Beta 4 is supporting the W3C Geo API.&nbsp;Awesome!",
					username:		"torgo",
					link:				"http://twitter.com/torgo/status/2377278764"
				},
				quote = {
					text:				"Don’t get me wrong on the iPhone it kicks, but on the desktop Hahlo 4 is flipping screaming&nbsp;amazing.",
					username:		"cwluc",
					link:				"http://twitter.com/Cwluc/status/2344928789"
				},
				quote = {
					text:				"Very cool, Hahlo can fetch current location from Safari on iPhone OS3. Very&nbsp;nice&nbsp;feature.",
					username:		"camielschoonens",
					link:				"http://twitter.com/camielschoonens/status/2343997969"
				},
				quote = {
					text:				"I like that it’s in safari because it doesn’t crash like the native&nbsp;apps.",
					username:		"jamms",
					link:				"http://twitter.com/jamms/status/2463169856"
				},
				quote = {
					text:				"Hahlo 4 just got hotter with fullscreen mode - awesome&nbsp;stuff.",
					username:		"tonyarnold",
					link:				"http://twitter.com/tonyarnold/status/2511220019"
				}
			];
		
		
		
		$('#quotes').ready(function(){
			
			quoteArray.sort(function() {return 0.5 - Math.random()});
			
			var o = "<ul>";
			for(var x=0;x<quoteArray.length;x++){
				var y = quoteArray[x].text.length;
				if(y<50){
					var c = " class='one'";
				} else if(y<80){
					var c = " class='two'";
				} else if(y<140){
					var c = " class='three'";
				}
				o += "<li><blockquote"+c+"><div><span class='q'>&ldquo;</span><span class='t'>"+quoteArray[x].text+"</span><cite><a href='"+quoteArray[x].link+"'>&mdash; @"+quoteArray[x].username+"</a></cite></div></blockquote></li>";
			}
			var z = quoteArray[0].text.length;
			if(z<50){var d = " class='one'";} else if(z<80){var d = " class='two'";} else if(z<140){var d = " class='three'";}
			o += "<li><blockquote"+d+"><div><span class='q'>&ldquo;</span><span class='t'>"+quoteArray[0].text+"</span><cite><a href='"+quoteArray[0].link+"'>&emdash; @"+quoteArray[0].username+"</a></cite></div></blockquote></li>";
			o += "</ul>";
			
			$('#quotes').html(o);
			
		});
		
		setInterval(function(){
			var cTop = $('#quotes ul').css('top');
			$('#quotes ul').animate({'top':parseInt(cTop)-300},1000,'swing',function(){
				if(parseInt(cTop)==-2700){
					$('#quotes ul').css('top',0);
				}
			});
		},10000);
		
		setInterval(function(){
			var shown = $('#brag ul li.show');
			if(shown.attr('id')=="lastStat"){
				shown.animate({'opacity':0},'slow',function(){$(this).removeClass('show').siblings().eq(0).animate({'opacity':1},'slow',function(){$(this).addClass('show');});});
			} else {
				shown.animate({'opacity':0},'slow',function(){$(this).removeClass('show').next().animate({'opacity':1},'slow',function(){$(this).addClass('show');});});
			}
		},6000);
		
		var portrait_screen_slide = setInterval(function(){
			var cLeft = $('#portrait_screen img').css('left');
			$('#portrait_screen img').animate({'left':parseInt(cLeft)-144},200,'swing',function(){
				if(parseInt(cLeft)==-1440){ //1584
					$('#portrait_screen img').css('left',0);
				}
			});
		},7500);
		
		var landscape_screen_slide = setInterval(function(){
			var cLeft = $('#landscape_screen img').css('left');
			$('#landscape_screen img').animate({'left':parseInt(cLeft)-217},200,'swing',function(){
				if(parseInt(cLeft)==-1085){ //1519
					$('#landscape_screen img').css('left',0);
				}
			});
		},8500);
		
		
	$('#promo').ready(function(){
				
		$('#portrait_scroll_right').click(function(event){
			event.preventDefault();
			clearInterval(portrait_screen_slide);
			var cLeft = $('#portrait_screen img').css('left');
			$('#portrait_screen img').animate({'left':parseInt(cLeft)-144},200,'swing',function(){
				if(parseInt(cLeft)==-1440){ //1584
					$('#portrait_screen img').css('left',0);
				}
			});
		});
		$('#portrait_scroll_left').click(function(event){
			event.preventDefault();
			clearInterval(portrait_screen_slide);
			var cLeft = $('#portrait_screen img').css('left');
			if(parseInt(cLeft)==0){
				$('#portrait_screen img').css('left',-1584); //1728
				cLeft = -1584; //1728
			}
			$('#portrait_screen img').animate({'left':parseInt(cLeft)+144},200,'swing');
		});
		
		$('#landscape_scroll_right').click(function(event){
			event.preventDefault();
			clearInterval(landscape_screen_slide);
			var cLeft = $('#landscape_screen img').css('left');
			$('#landscape_screen img').animate({'left':parseInt(cLeft)-217},200,'swing',function(){
				if(parseInt(cLeft)==-868){ //1302
					$('#landscape_screen img').css('left',0);
				}
			});
		});
		$('#landscape_scroll_left').click(function(event){
			event.preventDefault();
			clearInterval(landscape_screen_slide);
			var cLeft = $('#landscape_screen img').css('left');
			if(parseInt(cLeft)==0){
				$('#landscape_screen img').css('left',-1085); //1519
				cLeft = -1085; //1519
			}
			$('#landscape_screen img').animate({'left':parseInt(cLeft)+217},200,'swing');
		});
		
		
		$('#iphone_landscape').hoverIntent(function(){
			$('#iphone_landscape').animate({'top':147,'right':-75},'fast',function(){
				$(this).css('z-index',200).animate({'top':159,'right':0},'fast');
			});
			$('#landscape_screen').animate({'top':177,'left':734},'fast',function(){
				$(this).css('z-index',190).animate({'top':189,'left':674},'fast')
			});
			$('#iphone_portrait a').fadeOut();
			$('#iphone_landscape a').fadeIn(function(){$(this).css('display','block');});
			$('#iphone_portrait').animate({'top':-2,'left':500},'fast',function(){
				$(this).animate({'top':-14,'left':560},'fast');
			});
			$('#portrait_screen').animate({'top':67,'left':531},'fast',function(){
				$(this).animate({'top':55,'left':591},'fast')
			});
			$('#badge').animate({'top':-37,'left':620},'fast',function(){
				$(this).animate({'top':-49,'left':680},'fast');
			});
		},function(){
			$('#iphone_landscape').animate({'top':147,'right':-75},'fast',function(){
				$(this).css('z-index',50).animate({'top':135,'right':0},'fast');
			});
			$('#landscape_screen').animate({'top':177,'left':734},'fast',function(){
				$(this).css('z-index',40).animate({'top':165,'left':674},'fast')
			});
			$('#iphone_landscape a').fadeOut();
			$('#iphone_portrait a').fadeIn(function(){$(this).css('display','');});
			$('#iphone_portrait').animate({'top':-2,'left':500},'fast',function(){
				$(this).animate({'top':10,'left':560},'fast');
			});
			$('#portrait_screen').animate({'top':67,'left':531},'fast',function(){
				$(this).animate({'top':79,'left':591},'fast')
			});
			$('#badge').animate({'top':-37,'left':620},'fast',function(){
				$(this).animate({'top':-25,'left':680},'fast');
			});
			
		});
		
	});
	
})(jQuery);