//	speed for animations
var openSpeed = 200;
var closeSpeed = openSpeed;
var slideSpeed = 100;
var infoSpeed = 100;

// between open container and loading images
var imageLoadDelay = 200;
// between close container and open new one
var switchDelay = 100;

//	no currently active items
var activeId = false;
// var actInfo = false;
var actImg = false;
//video10 activity
var activevideo10 = false;
//video09 activity
var activevideo09 = false;
//video08 activity
var activevideo08 = false;
//map activity
var activeMap = false;
//sponsors activity
var activeSponsors = false;
//contact activity
var activeContact = false;
//presskit activity
var activePress = false;

var activewraparound = false;

// path for images
var imagepath = "http://www.designwalk.gr/images/dw_images/";
//pop-Up Window
var newwindow;


function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function getImages(id) {

	if(!allImages[id]) return;

	var images = allImages[id];
	var imageHolder = $("#ih"+id);
	var imageNav = $("#in"+id);
	var newContent = "";
	var newNavi = "";
	
	imageHolder.html("<div class=\"preloadbox\"><\/div>");
	
	// store new content
	for(i = 0; i < (images.length); i = i+1) {
		var newImage = "<img src=\""+imagepath+images[i]+"\" id=\"image"+i+"\" onclick=\"scrollImages("+id+","+i+"); return false;\" \/>";
		newContent = newContent + newImage;
		
		newNavi = newNavi + "<a href=\"#\" id=\"i"+i+"\" class=\"imagelink\" onclick=\"scrollImages("+id+","+i+"); return false;\">"+parseInt(i+1)+"</a> ";

	}

	// newNavi = "&#8592; " + newNavi; // larr
	newNavi = newNavi + "<a href=\"#\" onclick=\"prevImg("+id+"); return false;\">&lt;</a> <a href=\"#\" onclick=\"nextImg("+id+"); return false;\">&gt;</a>"; //rarr

	
	// setting variables
	actId = id;
	actImg = 0;
	
	if(images.length == 1)
	{
		$(".content .imagenav").slideUp("fast");	
	}
	//document.write(newNavi);
	///document.write(actId);
	///document.write(actImg);
	
	if(id==55)
	{
		$.preload(images, {
			base: imagepath,
			onFinish: function(){ 
				// callback on preload
	
				imageHolder.html(newContent);
				imageNav.html(newNavi);
				$("#i0").toggleClass("active");
				getImages(61);
			}
		});	
	}else{
		$.preload(images, {
			base: imagepath,
			onRequest: function(){ 
				// callback on preload
	
				imageHolder.html(newContent);
				imageNav.html(newNavi);
				$("#i0").toggleClass("active");
			}
		});
	}
	
	if(id==56)
	{
		$.preload(images, {
			base: imagepath,
			onFinish: function(){ 
				// callback on preload
	
				imageHolder.html(newContent);
				imageNav.html(newNavi);
				$("#i0").toggleClass("active");
				getImages(57); getImages(58); getImages(59);
			}
		});	
	}else{
		$.preload(images, {
			base: imagepath,
			onRequest: function(){ 
				// callback on preload
	
				imageHolder.html(newContent);
				imageNav.html(newNavi);
				$("#i0").toggleClass("active");
			}
		});
	}
	

}

function scrollImages(id, img) {
	
	// actImg = id;
	
	var imageHolder = $("#ih"+id);
	var ihx = $("#ih"+id).offset();
	// only accept images in exactly this imageholder
	var imagex = $("#ih"+id+" #image"+img).offset();
	//alert("#ih"+id);
	//alert("#image"+img);
	//dumpProps(imagex, parent);
	if(imagex == null){
		imagex = 0;
	}
	var diff = ihx['left'] - imagex['left'];
	if(diff == null){
		diff = 0;
	}
	
	$("#i"+actImg).toggleClass("active");
	actId = id;
	actImg = img;
	$("#i"+actImg).toggleClass("active");
	
	var newPos = diff + "px";
	imageHolder.animate({ marginLeft: newPos }, 300);
	return false;
}

function prevImg(id) {
	if(actImg == 0) var scrollimg = (allImages[id].length-1);
	else scrollimg = actImg - 1;
	if(scrollimg > allImages[id].length){
		scrollimg = 0;	
	}
	scrollImages(id, scrollimg);
	//alert(id)
	//alert(scrollimg);
}

function nextImg(id) {
	if(actImg == (allImages[id].length-1)) var scrollimg = 0;
	else scrollimg = actImg + 1;
	if(scrollimg > allImages[id].length){
		scrollimg = 0;	
	}
	scrollImages(id, scrollimg);
	//alert(id)
	//alert(scrollimg);
}

function clearContent(id) {
	$("#ih"+id).css("marginLeft", "0px");
	$("#ih"+id).html("");
	$("#in"+id).html("");
}

//Pop up
function poptastic(url){
	newwindow=window.open(url,'name','width=650,height=449,left=200,top=200');
	if (window.focus) {newwindow.focus()}
}

//Pop up Catalog
function popCatalog(url){
	newwindow=window.open(url,'name','width=704,height=650,left=200,top=10,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}


$(document).ready(function(){
	
	// hide content boxes
	$(".content").hide();
	
	// hide info boxes
	$(".infotext").hide();
	
	// project boxes slidetoggle
	$("div.data").click(function(event){
	
		var id = $(this).prev("a").attr("name");
		id = id.substring(1,id.length);
		var container = $("#c"+id);
		var data =  $("#data"+id);
		// $(this).parent().toggleClass("active");
		
		if(activeId && activeId == id) {
		// active = clicked -> close and empty
			data.removeClass("active");
			activeId = false;			
			container.slideToggle(closeSpeed, function() {
				// clear previously generated content
				clearContent(id); 
			});
			
		} else if (!activeId) {
		// no active -> open clicked

			data.addClass("active");
			activeId = id;
			
			container.slideToggle(openSpeed, function() { getImages(id); });
			//alert(id);
			/*if(id == 56)
			{
				container.slideToggle(openSpeed, function() { getImages(56); getImages(57); getImages(58); getImages(59);});
			}else{
				container.slideToggle(openSpeed, function() { getImages(id); });
			}*/
				
			
		} else if (activeId) {
		// close old, open new
			
			$("#data"+activeId).removeClass("active");
			data.addClass("active");
			
			$("#c"+activeId).slideToggle(closeSpeed, function() {
				clearContent(activeId); 
				activeId = id;
				setTimeout(function() {
					container.slideToggle(openSpeed, function() { getImages(id); });
				}, switchDelay);
			});
		}
			
		return false;
	});
	
	// 	slidetoggle infoboxes
	$(".video10 a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	// 	slidetoggle infoboxes
	$(".video09 a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	$(".video08 a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	$("#information #primary h1 a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h1").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	$(".hmap a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	$(".hsponsors a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	$("#information #secondaryB h2 a").click(function(event){
		$(this).toggleClass("active");
		$(this).parent("h2").next(".infotext").slideToggle(infoSpeed);
		return false;
	});
	
	/*hVideo10 activity*/
	$(".video10 a").click(function(event){
		if(activevideo10 == true) {
			activevideo10 = false;			
			$(".video10 a").css({'text-decoration' : 'none'});
		} else if (activevideo10 == false) {
			$(".video10 a").css({'text-decoration' : 'line-through'});
			activevideo10 = true;			
		}
	});
	
	/*hVideo09 activity*/
	$(".video09 a").click(function(event){
		if(activevideo09 == true) {
			activevideo09 = false;			
			$(".video09 a").css({'text-decoration' : 'none'});
		} else if (activevideo09 == false) {
			$(".video09 a").css({'text-decoration' : 'line-through'});
			activevideo09 = true;			
		}
	});
	
	/*hVideo09 activity*/
	$(".video08 a").click(function(event){
		if(activevideo08 == true) {
			activevideo08 = false;			
			$(".video08 a").css({'text-decoration' : 'none'});
		} else if (activevideo08 == false) {
			$(".video08 a").css({'text-decoration' : 'line-through'});
			activevideo08 = true;			
		}
	});
	
	/*hMap activity*/
	$(".hmap a").click(function(event){
		if(activeMap == true) {
			activeMap = false;			
			$(".hmap a").css({'text-decoration' : 'none'});
		} else if (activeMap == false) {
			$(".hmap a").css({'text-decoration' : 'line-through'});
			activeMap = true;			
		}
	});
	
	/*hSponsors activity*/
	$(".hsponsors a").click(function(event){
		if(activeSponsors == true) {
			activeSponsors = false;			
			$(".hsponsors a").css({'text-decoration' : 'none'});
		} else if (activeSponsors == false) {
			$(".hsponsors a").css({'text-decoration' : 'line-through'});
			activeSponsors = true;			
		}
	});
	
	/*hContact activity*/
	$(".hcontact a").click(function(event){
		if(activeContact == true) {
			activeContact = false;			
			$(".hcontact a").css({'text-decoration' : 'none'});
		} else if (activeContact == false) {
			$(".hcontact a").css({'text-decoration' : 'line-through'});
			activeContact = true;			
		}
	});
	
	/*presskit activity*/
	$(".presskit a").click(function(event){
		if(activePress == true) {
			activePress = false;			
			$(".presskit a").css({'text-decoration' : 'none'});
		} else if (activePress == false) {
			$(".presskit a").css({'text-decoration' : 'line-through'});
			activePress = true;			
		}
	});
	
	/*wraparound activity*/
	$("#wraparounds a").click(function(event){
		if(activewraparound == true) {
			activewraparound = false;			
			$(this).find(".data .title h5").css({'text-decoration' : 'none'});
		} else if (activewraparound == false) {
			$(this).find(".data .title h5").css({'text-decoration' : 'line-through'});
			activewraparound = true;			
		}
	});
	
	
	//  h1 years functions
	//left column
	$("h1#10 a").css({'text-decoration' : 'line-through'});
	$("#poster09").hide();
	$("#poster08").hide();
	$("#poster07").hide();
	$("#sponsors09").slideUp("fast");
	$("#sponsors08").slideUp("fast");
	$("#sponsors07").slideUp("fast");
	$("#map09").slideUp("fast");
	$("#map08").slideUp("fast");
	$("#map07").slideUp("fast");
	$("#video10").fadeIn("fast");
	$("#video09").slideUp("fast");
	$("#video08").slideUp("fast");
	
	$("#catalog").fadeIn("fast");
	
	//right column
	$("div#main ul#dw09").slideUp("fast");
	$("div#main ul#dw08").slideUp("fast");
	$("div#main ul#dw07").slideUp("fast");
	
	$("h1#10 a").click(function () {	
		$("div#main ul#dw10").fadeIn("fast");
		$("div#main ul#dw09").slideUp("fast");
		$("div#main ul#dw08").slideUp("fast");
		$("div#main ul#dw07").slideUp("fast");
		
		$("#sponsors10").slideDown("fast");
		$("#sponsors09").slideUp("fast");
		$("#sponsors08").slideUp("fast");
		$("#sponsors07").slideUp("fast");
		$("#map10").slideDown("fast");
		$("#map09").slideUp("fast");
		$("#map08").slideUp("fast");
		$("#map07").slideUp("fast");
		
		$(this).css({'text-decoration' : 'line-through'});
		$("h1#09 a").css({'text-decoration' : 'none'});
		$("h1#08 a").css({'text-decoration' : 'none'});
		$("h1#07 a").css({'text-decoration' : 'none'});
		$("#poster10").fadeIn("fast");
		$("#poster09").slideUp("fast");
		$("#poster08").slideUp("fast");
		$("#poster07").slideUp("fast");
		
		$("#presskit").fadeIn("fast");
		
		$("#video10").fadeIn("fast");
		$("#video09").slideUp("fast");
		$("#video08").slideUp("fast");
		
		$(".footerdecker").fadeIn("fast");
	});
	
	$("h1#09 a").click(function () {	
		$("div#main ul#dw10").slideUp("fast");
		$("div#main ul#dw09").fadeIn("fast");
		$("div#main ul#dw08").slideUp("fast");
		$("div#main ul#dw07").slideUp("fast");
		
		$("#sponsors10").slideUp("fast");
		$("#sponsors09").slideDown("fast");
		$("#sponsors08").slideUp("fast");
		$("#sponsors07").slideUp("fast");
		$("#map10").slideUp("fast");
		$("#map09").slideDown("fast");
		$("#map08").slideUp("fast");
		$("#map07").slideUp("fast");
		
		$(this).css({'text-decoration' : 'line-through'});
		$("h1#10 a").css({'text-decoration' : 'none'});
		$("h1#08 a").css({'text-decoration' : 'none'});
		$("h1#07 a").css({'text-decoration' : 'none'});
		$("#poster10").slideUp("fast");
		$("#poster09").fadeIn("fast");
		$("#poster08").slideUp("fast");
		$("#poster07").slideUp("fast");
		
		$("#presskit").slideUp("fast");
		
		$("#video10").slideUp("fast");
		$("#video09").fadeIn("fast");
		$("#video08").slideUp("fast");
		
		$(".footerdecker").slideUp("fast");
	});
	
	$("h1#08 a").click(function () {
		$("div#main ul#dw10").slideUp("fast");
		$("div#main ul#dw09").slideUp("fast");
		$("div#main ul#dw08").fadeIn("fast");
		$("div#main ul#dw07").slideUp("fast");
		
		$("#sponsors10").slideUp("fast");
		$("#sponsors09").slideUp("fast");
		$("#sponsors08").slideDown("fast");
		$("#sponsors07").slideUp("fast");
		$("#map10").slideUp("fast");
		$("#map09").slideUp("fast");
		$("#map08").slideDown("fast");
		$("#map07").slideUp("fast");
		
		$(this).css({'text-decoration' : 'line-through'});
		$("h1#09 a").css({'text-decoration' : 'none'});
		$("h1#10 a").css({'text-decoration' : 'none'});
		$("h1#07 a").css({'text-decoration' : 'none'});
		$("#poster10").slideUp("fast");
		$("#poster09").slideUp("fast");
		$("#poster08").fadeIn("fast");
		$("#poster07").slideUp("fast");
		
		$("#presskit").slideUp("fast");
		
		$("#video10").slideUp("fast");
		$("#video09").slideUp("fast");
		$("#video08").fadeIn("fast");
		
		$(".footerdecker").slideUp("fast");
	});
	
	$("h1#07 a").click(function () {
		$("div#main ul#dw10").slideUp("fast");
		$("div#main ul#dw09").slideUp("fast");
		$("div#main ul#dw08").slideUp("fast");
		$("div#main ul#dw07").fadeIn("fast");
		
		$("#sponsors10").slideUp("fast");
		$("#sponsors09").slideUp("fast");
		$("#sponsors08").slideUp("fast");
		$("#sponsors07").slideDown("fast");
		$("#map10").slideUp("fast");
		$("#map09").slideUp("fast");
		$("#map08").slideUp("fast");
		$("#map07").slideDown("fast");
		
		$(this).css({'text-decoration' : 'line-through'});
		$("h1#09 a").css({'text-decoration' : 'none'});
		$("h1#08 a").css({'text-decoration' : 'none'});
		$("h1#10 a").css({'text-decoration' : 'none'});
		$("#poster10").slideUp("fast");
		$("#poster09").slideUp("fast");
		$("#poster08").slideUp("fast");
		$("#poster07").fadeIn("fast");
		
		$("#presskit").slideUp("fast");
		
		$("#video10").slideUp("fast");
		$("#video09").slideUp("fast");
		$("#video08").slideUp("fast");
		
		$(".footerdecker").slideUp("fast");
	});
	
	
	

	
}); // document.ready end