var windowWidth;
var inProject = false;
var projectNumber;
var numProjects;
var currentPic = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var currentPicLast = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var pHas = new Array(200);
var video = new Array(200);

SA.redirection_mobile ({param:"isDefault", mobile_url : "liebeundmango.de/portfolio3/mobile/", cookie_hours : "1" });




function showTweets(elem, username, number)
	{
		var html = '<div>';
 
 
 
	var tweetFeed = 'http://twitter.com/status/user_timeline/' + username + '.json?count=' + number + '&callback=?'
		$.getJSON(tweetFeed, function(d)
		{
 
 
			$.each(d, function(i,item)
			{
				html+='<div class="twitterItem">'+i+item.text+'</div>';
			})
			html+="</div>";
			
			
			elem.children().fadeOut('fast',function() {
				
				elem.append(html);
			})
		})
	}
		

$(document).ready(function() {
					$.easing.def = "easeOutExpo";
					//TWITTER
					/*$('#error').remove();
					$('#preload').show();
					showTweets($('#tweets'), 'adblaufasan', 4)*/
					
					
					//MESSAGE
					$("#infoApture").delay(4000).fadeOut(500);
					
					
					
					$(".tweet").tweet({
					            username: "adblaufasan",
					            join_text: "auto",
					            avatar_size: 0,
					            count: 3,
					            auto_join_text_default: "i said,", 
					            auto_join_text_ed: "i",
					            auto_join_text_ing: "i were",
					            auto_join_text_reply: "i replied to",
					            auto_join_text_url: "i were checking out",
					            loading_text: "loading tweets..."
					        });
					
					
					var aboutMeVisible = false;
					$("#aboutBt").click(function() {
						if(!aboutMeVisible) {
							$("#aboutMe").css('cursor', 'default');
							$("#aboutMe").animate({
								marginTop: 0
							
							}, 500);
							aboutMeVisible = true;
						}
						
					});
					$("#aboutCloseButton").click(function() {
						
						$("#aboutMe").animate({
							marginTop: '-490px'
						
						}, 500, function() {
							$(this).css('cursor', 'pointer');
							aboutMeVisible = false;
						});
						
					
					
					});
					$('#aboutMe').mouseenter(function() {
						if(!aboutMeVisible) {
							$(this).stop(true, false);
							$(this).delay(200).animate({
								marginTop: '-475px'
							}, 300);
						} else {
						}
					});
					$('#aboutMe').mouseleave(function() {
						if(!aboutMeVisible) {
							$(this).stop(true, false);
							$(this).animate({
								marginTop: '-490px'
							}, 200);
						} else {
						}
					});
					$('#aboutMe').click(function() {
						if(!aboutMeVisible) {
							$(this).css('cursor', 'default');
							$("#aboutMe").animate({
								marginTop: 0
							
							}, 500);
							aboutMeVisible = true;
						}
					});

					currentPicLast[projectNumber] = currentPic[projectNumber];


					
					imageresize();//Triggers when document first loads      

					 $(window).bind("resize", function(){//Adjusts image when browser resized  
					 	imageresize();  
					 }); 

					function imageresize() {  
						 var contentwidth = $(window).width() - 40; 
						 $('#load').width(contentwidth);


						 if(1 == 1) {
						 	$('.top').width(280*3-40);
							$('#footer').width(280*3-40);
							$(".layoutDiv").css({
								marginLeft: -((280*3)/2),
								left: '50%'									
							});
							$("#inhalt").css({
								width: 280*3,
							});
							$("#inhalt2").css({
								width: 280*3-40,
							});
							
						 }  
						 /*if((contentwidth) < (280*5) && (contentwidth) > 280*4) {
						 	$('.top').width(280*4-40); 
							$('#footer').width(280*4-40);
							$(".layoutDiv").css({
								marginLeft: -((280*4)/2),
								left: '50%'									
							});
							$("#inhalt").css({
								width: 280*4,
							});
							$("#inhalt2").css({
								width: 280*4-40,
							});
							
						 } */ 
						 /*if((contentwidth) > 280*5) {
						 	$('.top').width(280*5-40);
							$('#footer').width(280*5-40);
							$(".layoutDiv").css({
								marginLeft: -((280*5)/2),
								left: '50%'									
							});
							$("#inhalt").css({
								width: 280*5,
							});
							$("#inhalt2").css({
								width: 280*5-40,
							});
						 }*/
					} 

					if(projectNumber > -1) {
												//$("#inhalt").fadeOut(250);
												//$("#inhalt2").delay(250).fadeIn(150);
												//projectNumber = $(this).parent(".webLink").attr('id').replace('p', '');
												$("#infoApture").hide();
												$("#imagePos").html(currentPic[projectNumber]+1);
												$("#imageMax").html(pHas[projectNumber]);
												if(video[projectNumber] > 0) {
													$("#detailPicture").children("#picture").remove();
													$("#detailPicture").html('');
													var someimage = $.ajax({
													   type: "GET",
													   url: "content/web/"+projectNumber+"_0.html",
													   success: function(data) {
													   	$("#detailPicture").html(data);
													   }
													 });
												 } else {
												 		
													 $("#detailPicture").children("#picture").remove();
													 $("#detailPicture").html('');
													 $("#detailPicture").css('opacity', '0');
													 $("#detailPicture").image("content/web/"+projectNumber+"_"+currentPic[projectNumber]+".jpg",function(){
													 	$("#detailPicture").delay(20).animate({
													 		opacity: 1
													 	}, 100);
													 });
												 }
					
					
					}
					
					
					
					
					
					
					
					
					
					
					
					
					//clicks					
					
					$("#next").live('click', function() {
						if(currentPic[projectNumber] < pHas[projectNumber]-1) {
							currentPic[projectNumber]++;
						} else {
							currentPic[projectNumber] = 0;
						}
						changePicture();
									
					});
					$("#prev").live('click', function() {
						if(currentPic[projectNumber] > 0) {
							currentPic[projectNumber] += -1;
						} else {
							currentPic[projectNumber] = pHas[projectNumber]-1;
						}
						changePicture();		
					});
					
					
					$("#smallProjects").hover(function() {
						$("#hint_others").animate({
							opacity: 0.15
						}, 100);
						}, function() {
						$("#hint_others").animate({
							opacity:0
						}, 100);
					
					})
					
					
					$("#topInfo span").click(function() {
						
						
						
						if(projectNumber > -1) {
							
							
							
							
							
							
							
							$("#hint_leftright").animate({
								opacity:1
							}, 150).delay(4000).animate({
								opacity:0
							}, 350);
							$("#hint_updown").animate({
								opacity:1
							}, 150).delay(4000).animate({
								opacity:0
							}, 350);
						} else {
							$("#aboutmeTop").animate({
								opacity:0
							}, 50);
							$("#hint_click").animate({
								opacity: 1
							}, 150).delay(4000).animate({
								opacity:0
							}, 350);
						}
					
					});
					
					
					//KEYBOARD Nav
					
					$(document).keydown(function (e) {
					  var keyCode = e.keyCode || e.which,
					      arrow = {left: 37, up: 38, right: 39, down: 40 };
					  if(projectNumber > -1) {
						  switch (keyCode) {
						    case arrow.left:
						      if(currentPic[projectNumber] > 0) {
						      	currentPic[projectNumber] += -1;
						      	
						      } else {
						      	currentPic[projectNumber] = pHas[projectNumber]-1;
						      }
						      changePicture();
						      $("#prev").addClass("pictureNavBtPressed").delay(1000).removeClass("pictureNavBtPressed");	
						    break;
						    case arrow.up:
						      if(projectNumber == numProjects-1) {
						      	open("?p=0", "_self");	
						      } else {
						      	open("?p="+(projectNumber+1), "_self");
						      }
						    break;
						    case arrow.right:
						      if(currentPic[projectNumber] < pHas[projectNumber]-1) {
						      	currentPic[projectNumber]++;
						      } else {
						      	currentPic[projectNumber] = 0;
						      }
						      changePicture();
						      $("#next").addClass("pictureNavBtPressed").delay(200).removeClass("pictureNavBtPressed");
						    break;
						    case arrow.down:
						      if(projectNumber == 0) {
						      	open("?p="+(numProjects-1), "_self");	
						      } else {
						      	open("?p="+(projectNumber-1), "_self");
						      }
						    break;
						  }
					  } else {
					  	switch (keyCode) {
					  	  case arrow.left:
					  	    //..
					  	  break;
					  	  case arrow.up:
					  	    //..
					  	  break;
					  	  case arrow.right:
					  	    //..
					  	  break;
					  	  case arrow.down:
					  	    //..
					  	  break;
					  	}					  
					  }
					});
					
					
					
					
				});
				
				
				
				
				
				
				
				
				
				
				
				
				
				function changePicture() {
					var lastPicture = currentPicLast[projectNumber]+1;
					var nowPicture = currentPic[projectNumber]+1;
					var thisThing = "#imgInd"+currentPic[projectNumber]+"";
					$("#imgInd"+lastPicture).animate({
						backgroundColor: "#ddd"
					}, 100, function() {
						$("#imgInd"+nowPicture).animate({
							backgroundColor: "#ffdd00"
						}, 100);							
					});
					$("#detailPicture").animate({
						opacity: 0
						}, 200, function() {
							
							currentPicLast[projectNumber] = currentPic[projectNumber];
							$("#imagePos").html(currentPic[projectNumber]+1);
							if(currentPic[projectNumber] == 0 && video[projectNumber] > 0) {
								
								$("#detailPicture").children("#picture").remove();
								$("#detailPicture").html('');
								var someimage = $.ajax({
								   type: "GET",
								   url: "content/web/"+projectNumber+"_0.html",
								   success: function(data) {
								   	$("#detailPicture").html(data);
								   	$("#detailPicture").animate({
								   		opacity: 1,
								   	}, 200);
								   }
								 });
								
								
							} else if (currentPic[projectNumber] == 1 && video[projectNumber] > 1) {
								$("#detailPicture").children("#picture").remove();
								$("#detailPicture").html('');
								var someimage = $.ajax({
								   type: "GET",
								   url: "content/web/"+projectNumber+"_1.html",
								   success: function(data) {
								   	$("#detailPicture").html(data);
								   	$("#detailPicture").animate({
								   		opacity: 1,
								   	}, 200);
								   }
								 });
						
							} else {
								
								if(video[projectNumber] == 1) {
									$("#detailPicture").html('');
								}						
								$("#detailPicture").children("#picture").remove();
								$("#detailPicture").html('');
								$("#detailPicture").image("content/web/"+projectNumber+"_"+currentPic[projectNumber]+".jpg",function(){
									$("#detailPicture").animate({
										opacity: 1,
									}, 200);
								});
							}
						});
						
				};
				
				
