/////////////////////////////////////////////////////////////////////// The mainmenu
function menu(id)
{
	document.images[0].src = document.images[0].src.replace('_active.png', '.png');
	document.images[1].src = document.images[1].src.replace('_active.png', '.png');
	document.images[2].src = document.images[2].src.replace('_active.png', '.png');
	document.images[4].src = document.images[4].src.replace('_active.png', '.png');
	document.images[5].src = document.images[5].src.replace('_active.png', '.png');
	document.images[6].src = document.images[6].src.replace('_active.png', '.png');
	
	if( id != 3 )
	{
		image = document.images[id].src;
		document.images[id].src = image.replace('.png', '_active.png');
		$('#site').animate({'height' : '679px'});
		
		// Checking for ipad + logo update
		var checkDevice = $('#CheckDevice').val();
		if(checkDevice == 1)
		{
				$('.logo').attr({'src' : './assets/images/logo_ken-picton_over.png'});
		}
		
	}
	if(id == 3)
	{
		$('#site').animate({'height' : '848px'}, 500);
		$('.logo').attr({'src' : './assets/images/logo_ken-picton.png'});
	}
	
}

/////////////////////////////////////////////////////////////////////// Drag and drop
var dragsort = ToolMan.dragsort()
var junkdrawer = ToolMan.junkdrawer()

window.onload = function() {
	//junkdrawer.restoreListOrder("boxes")

	//dragsort.makeListSortable(document.getElementById("boxes"), saveOrder)
}

function verticalOnly(item) {
	item.toolManDragGroup.verticalOnly()
}

function speak(id, what) {
	var element = document.getElementById(id);
	element.innerHTML = 'Clicked ' + what;
}

function saveOrder(item) {
	var group = item.toolManDragGroup
	var list = group.element.parentNode
	var id = list.getAttribute("id")
	if (id == null) return
	group.register('dragend', function() {
		ToolMan.cookies().set("list-" + id, 
				junkdrawer.serializeList(list), 365)
	})
}

/////////////////////////////////////////////////////////////////////// Slider
$().ready(function() {
	$('#coda-slider-1').codaSlider();
});

/////////////////////////////////////////////////////////////////////// The Salon: Press pagina
scrollStep	= 2;
timerLeft	= "";
timerRight	= "";

function scrollDivLeft(id)
{
  clearTimeout(timerRight) 
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",1)
}

function scrollDivRight(id)
{
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",1)
}

function stopMe()
{
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

// Nieuwe functie: schuiven van het div-blok
Pressvalue = '';

function openInfo(id)
{	
	
	$('.slideDownload').css( { height:"00px", width:"10px" } );
	$('.slideDownload#pressDown2-'+id).css( { height:"220px", width:"150px" } );
	
	$('#changeFrameI').attr({'src' : 'http://www.kenpicton.com/assets/pageFlip/index.php?startId='+id}); 
	 
	//console.log(id); 

	if( Pressvalue != 'down' )
	{
		$('.slideContent2').css( { height:"0px", width:"815px" } );
		$('.slideContent2#press-'+id).css( { height:"290px", width:"595px" } );
		
		$('#infoSlider').animate( { height:"320px" }, 300 );
		$('#infoSlider').animate( { height:"290px" }, 200 );
		Pressvalue = 'down';
	}
	else
	{
		$('#infoSlider').animate( { height:"0px" }, 300 );
		
		$('.slideContent2').animate( { height:"0px", width:"595px" }, 300 );
		$('.slideContent2#press-'+id).animate( { height:"290px", width:"595px" }, 10 );
		
		$('#infoSlider').animate( { height:"320px" }, 300 );
		$('#infoSlider').animate( { height:"290px" }, 200 );
		Pressvalue = 'down';
	}
}

function hideHomeBanner()
{
	$('#homeBanner').fadeOut('fast');
}


var state = false;
function loadImage(url, type)
{
	
	if(state == true)
	{
		$('#imageHolderTweets').animate({'height' : '0px'}, 600);	  
		if(type == 'twitpic')
		{
			$('#twitImage').attr({'src' : 'http://twitpic.com/show/large/'+url });
		}
		
		else if(type == 'yfrog')
		{ 
			$('#twitImage').attr({'src' : 'http://yfrog.com/'+url+':medium' });
		} 
		else   
		{
			window.open(url, '_blank');
		}
		
		setTimeout(function(){
			if(type == 'link')
			{
				
			}
			else
			{ 
				$('#imageHolderTweets').animate({'height' : '240px'}, 600);	  
			}		
		}, 2500);
		
		state = false;
	}
	else if( state == false)
	{
		
		if(type == 'twitpic')
		{
			$('#twitImage').attr({'src' : 'http://twitpic.com/show/large/'+url });
		}	
		
		else if(type == 'yfrog')
		{ 
			$('#twitImage').attr({'src' : 'http://yfrog.com/'+url+':medium' });
		} 
		else   
		{
			var checkLeave = confirm('You are about to go to an external link you want to proceed?');
			
			if(checkLeave)
			{
				window.open(url, '_blank');
			}
			
			
		}
		
		// checking the height of image \
		
		
		setTimeout(function(){
		
			if(type == 'link')
			{
				
			}
			else
			{
				$('#imageHolderTweets').animate({'height' : '240px'}, 600);	  
				$('#rightMenuArrow').animate({marginTop : '-40px' })
				$('#twitterContent').animate({'height' : '200px'}, 600);	  

			}
		}, 2500);
		state = true;
	}
	
		if(type == 'twitpic')
		{
			$('#gotoUrlTweet').val('http://twitpic.com/'+url);
		}	
		
		else if(type == 'yfrog')
		{ 
			$('#gotoUrlTweet').val('http://yfrog.com/'+url);
		} 
	
	
		setTimeout("animateTweetImage("+state+"); ", 3500);
}

function gotoTweetUrl()
{
	var urlVal = 	$('#gotoUrlTweet').val();
	window.open(urlVal, '_blank');
}

function animateTweetImage()
{
	
	var imgHeight = $('#twitImage').height();
	TrueMarginValue = parseInt(imgHeight) - 240;
	$('#twitImage').animate({marginTop : '-'+TrueMarginValue+'px'}, 15000);	
	$('#twitImage').animate({marginTop : '0px'}, 15000);	

}


function closeTweetImage()
{
		$('#rightMenuArrow').animate({marginTop : '160px' });

		$('#twitterContent').animate({'height' : '407px'}, 600);	  
		
		$('#imageHolderTweets').animate({'height' : '0px'}, 600);	  
		$('#twitImage').animate({marginTop : '0px'}, 900);	
		state = false;
		console.log('test');
}


$(document).ready(function()
{
	// Device Check 
	var CheckIpad =  $('#CheckDevice').val(); 
	if(beginPage != "3" && CheckIpad == "1" )
	{
		$(".logo").attr({"src" : "./assets/images/logo_ken-picton_over.png"});
	}

});
