
//Checking if this is a iPhone/iPod
try{
var version = get_webkit_version();
var iPhone_regex = /iPhone|iPod/;
var result = version['browser'].search(iPhone_regex);
if (result != -1) {
window.location = "iphone/";
}
}
catch(err){;}

Cufon.replace('#content_home .home h2, #content_home .home h3, #content_home .home a.more, #content_home .twitter h2, #content_home .twitter a.more');

$(document).ready(function(){
	// Manage Slideshow
	$("#project_slideshow div.container").easySlider({
		controlsShow:	false,
		speed: 			400,
		auto:			true,
		pause:			5000,
		continuous:		true
	});

	// Twitter scroll
	
	scroll_container = $("#content_home div.twitter div.all_tweets");
	up_element = $("#content_home div.twitter a.up");
	down_element = $("#content_home div.twitter a.down");
	max_speed = 10;
	current_speed = 0;
	acceleration = 0.3;
	
	// do not edit
	arrows_height = parseInt(up_element.height());
	
	scrolling = false;
	scrolling_direction = false;
	
	scroll_container.html('<div class="scroller">'+scroll_container.html()+'</div>');
	scrollable_div = scroll_container.find("div.scroller");
	scrollable_div.css("position", "absolute");
	scrollable_div.css("top", "0px");
	
	height = scrollable_div.height();
	
	if(height > scroll_container.height())
	{
		down_element.hover(
			function(){
				scrolling = true;
				scrolling_direction = "down";
			},
			function(){
				scrolling = false;
			}
		);
		up_element.hover(
			function(){
				scrolling = true;
				scrolling_direction = "up";
			},
			function(){
				scrolling = false;
			}
		);
		scrollTimer = setInterval(scrollDiv, 25);
	}
	else
	{
		down_element.css('background-position', '0px -'+(arrows_height*2)+'px');
		up_element.css('background-position', '0px -'+(arrows_height*2)+'px');
	}
	
	$isIE = false;
	if($("#projects div.menu ul li:first a span").find('cufon').hasClass('cufon-vml'))
	{
		$isIE = true;
	}
	if($isIE)
	{
		$("#projects div.menu ul li a span").hide();
	}
	else
	{
		$("#projects div.menu ul li a span").fadeTo(0, 0);
	}
	$("#projects div.menu ul li a").hover(
		function(){
			if($isIE)
			{
				$(this).find("span").show();
			}
			else
			{
				$(this).find("span").stop().fadeTo(100,1.0);
			}
		},
		function(){
			if($isIE)
			{
				$(this).find("span").hide();
			}
			else
			{
				$(this).find("span").stop().fadeTo(250,0);
			}
		}
	);
	
});


 
function scrollDiv()
{
	if(scrolling && current_speed < max_speed)
	{
		current_speed = current_speed + acceleration;
		if(current_speed > max_speed)
		{
			current_speed = max_speed;
		}
	}
	else if(!scrolling && current_speed > 0)
	{
		current_speed = current_speed - acceleration;
		if(current_speed < 0)
		{
			current_speed = 0;
		}
	}
	
	var current_pos = parseInt(scrollable_div.css("top"));
	//alert(':current pos: '+scrollable_div.css("top"));
	
	if(current_pos <= 0 - height + scroll_container.height())
	{
		down_element.css('background-position', '0px -'+(arrows_height*2)+'px');
	}
	else if(scrolling && scrolling_direction == "down")
	{
		down_element.css('background-position', '0px -'+(arrows_height)+'px');
	}
	else
	{
		down_element.css('background-position', '0px 0px');
	}
	
	if(current_pos >= 0)
	{
		up_element.css('background-position', '0px -'+(arrows_height*2)+'px');
	}
	else if(scrolling && scrolling_direction == "up")
	{
		up_element.css('background-position', '0px -'+(arrows_height)+'px');
	}
	else
	{
		up_element.css('background-position', '0px 0px');
	}
	
	
	if(scrolling_direction == "down")
	{
		var next_pos = current_pos - Math.round(current_speed);
		
		if (next_pos < 0 - height + scroll_container.height())
		{
			next_pos = 0 - height + scroll_container.height();
			current_speed = 0;
		}
		scrollable_div.css("top", next_pos);
	}
	if(scrolling_direction == "up")
	{
		var next_pos = current_pos + Math.round(current_speed);
		
		if (next_pos > 0)
		{
			next_pos = 0;
			current_speed = 0;
		}
		
		scrollable_div.css("top", next_pos);
	}
}