 $(document).ready( function(){
				
	
	
	 var cur_project = -1;
	 var cur_photos_num;
	 var cur_photos;
	 var tim;
	 
	 $('.hfade').innerfade({ 
	 speed: 'slow', 
	 timeout: 3000, 
	 type: 'sequence', 
	 containerheight: '400px' });
							 
	$('#arrow_right').click (function() {
			
			if (cur_photo_index < (cur_photos_num - 1)) {
				cur_photo_index++;
				
				
			}	
			else { cur_photo_index = 0; }
			
			$('#photo_area').fadeOut("fast", function() {
			
			$(this).html('<a class="bigimage" href="/imported/products/' + cur_photos[cur_photo_index].filename + '"><img src="/imported/products/' + cur_photos[cur_photo_index].filename + '" width=502 height=375 border=0></a>');
			Shadowbox.setup("a.bigimage", {				
			});
			
			$(this).fadeIn("fast");
			});
			
	});
	
	
	
	$('#arrow_left').click (function() {
			
			cur_photo_index--;
			
			if (cur_photo_index < 0) {
				cur_photo_index = cur_photos_num-1;
			}	
			
			$('#photo_area').fadeOut("fast", function() {
			
			$(this).html('<a class="bigimage" href="/imported/products/' + cur_photos[cur_photo_index].filename + '"><img src="/imported/products/' + cur_photos[cur_photo_index].filename + '" width=502 height=375 border=0></a>');
			Shadowbox.setup("a.bigimage", {				
			});
			
			$(this).fadeIn("fast");
			});
			
	});
	
	
$('.semitrans').mouseover (function() {
	
	//$(this).css({"background-color":"transparent"});
	if (cur_project != $(this).attr('pid'))
		$(this).fadeTo(200,0);
//	$(this).css({"border":"3px solid red"});
});

$('.semitrans').mouseout (function() {
	
	if (cur_project != $(this).attr('pid'))
		$(this).fadeTo(200,0.6);
	//$(this).css({"background-color":"#359cbb"});
	//$(this).css({"border":"0px solid red"});
	
});

 	$('.semitrans').click (function() {
		
		$('.semitrans').fadeTo(0,0.6);
		$(this).fadeTo(0,0);
		
		$('#photo_area').fadeOut("fast");
		$('#arrow_left').hide("fast");
		$('#arrow_right').hide("fast");
				
		cur_project = $(this).attr('pid');
		
		$.getJSON("ajax.php?pid=" + $(this).attr('pid'), 
			function(json){

				var l_str;
				var s_str;
				var y_str;
				if (curlang == "gr") {
					l_str = "περιοχή";
					s_str = "επιφάνεια";
					y_str = "έτος";
				}
				else {
					l_str = "location";
					s_str = "size";
					y_str = "year";
				
				}
					
			var data = '<BR><BR><div style="font-size:11px"><span style="color:#379bbd">' + json.title + '</span><BR>'+l_str+' <span style="color:#379bbd">' + json.location + '</span><BR>'+s_str+' <span style="color:#379bbd">' + json.m2 + ' m2</span><BR>'+y_str+' <span style="color:#379bbd">' + json.year + '</span><BR>' + json.text + '</div>';
			
			cur_photos_num = parseInt (json.photos_cnt);
			
			if (cur_photos_num > 1) {
				$('#arrow_left').show("fast");
				$('#arrow_right').show("fast");
			}	
			else {	
				$('#arrow_left').hide("fast");
				$('#arrow_right').hide("fast");
			}	
				
			$('#content_top').html(data);
			
			$('#photo_area').fadeOut("fast", function() {
			


			
			$(this).html('<a class="bigimage" href="/imported/products/' + json.photo[0].filename + '"><img src="/imported/products/' + json.photo[0].filename + '" width=502 height=375 border=0></a>');
			$(this).fadeIn("fast");
			Shadowbox.setup("a.bigimage", {
				
			});
			});
			
			
			
			cur_photos = json.photo.slice()
			cur_photo_index = 0;
			
			
			
		});

  
		
	});

	$('.scroll-pane').jScrollPane({animateTo:true, animateInterval:50, animateStep:5});
		
	// set up the links
	$('a.scroll-to-element-demo').bind(
		'click',
		function()
		{
		
			$this = $(this);
			var amount = parseInt($(this).attr('rel'));
			var destinationSelector = $(this).attr('rel');
			$('.scroll-pane', $this.parent().parent().parent()).each(
				function()
				{
					this.scrollBy(amount);
				}
			);
			return false;
		}
	);
	
	
	$('.scroll-pane-news').jScrollPane({animateTo:true, animateInterval:50, animateStep:5});
		
	// set up the links
	$('a.scroll-to-element-demo-news').bind(
		'click',
		function()
		{
		
			$this = $(this);
			var amount = parseInt($(this).attr('rel'));
			var destinationSelector = $(this).attr('rel');
			$('.scroll-pane-news', $this.parent().parent().parent()).each(
				function()
				{
					this.scrollBy(amount);
					if (amount < 0 && curnews_index > 0)
						curnews_index--;
					if (amount > 0 && curnews_index < curnews_max -1)	
						curnews_index++;
					//alert(curnews_index);
					$(".scr_news").removeClass("ntitlesel");
					$("#scr_news_"+curnews_index).addClass("ntitlesel");
					
					updatenews (curnews_index);

			
				}
			);
			return false;
		}
	);

	var curnews_index = 0;
	
	

	function updatenews(curnews_index) {
		$.getJSON("ajaxnews.php?offset=" + curnews_index + "&cid="+curnews_cat, 
					function(json){
						$('#topbox1').html(json.title+'<BR>'+json.text);
						$('#content').html('<img width=1000 height=362 src="/imported/news/'+json.filename+'">');
						
					});
	}
	

	$('.tphotosc').click (function() {
	
		var tid = parseInt($(this).attr('rel'));
	
		//if (tid == 5)
		//	$('#topbox1').fadeOut();
		//else
		//	$('#topbox1').fadeIn();		
			//alert(tid);
		$.getJSON("ajaxteam.php?tid=" + tid, 
					function(json){
					
						$('#ttitle_bot').html('<span style="font-size:14px">'+json.title+'</span><BR><span style="font-size:10px">'+architect_str+'</span><BR><BR><img src="/phpthumb/phpThumb.php?src=/imported/team/'+json.filename+'&w=140">');
						$('#tbio_bot').html(json.bio);
						
					});
			
			
	});


	var product_index;
	var product_images = new Array();
	var product_images_filenames = new Array();
	var product_images_loaded = new Array();
	
	function showSliderImage (pindex){
	
	
		//$("#pr_bigback").html("<img src='/imported/products/"+product_images[pindex]+"'>");
		$("#pr_bigback").empty();
		$("#pr_bigback").append(product_images[pindex]);
	
	}
	
	
	function slider_image_clicked (pid) { 
			
			
		$('#pr_trans').css("opacity", ".80");
		$('#pr_trans').css("filter", "alpha(opacity=80)");
		$('#pr_trans').css("-moz-opacity", "0.8");

		
			$.getJSON("ajax_get_project_info.php?pid=" + pid+"&lang="+clang, 
						function(json){
						
								//$("#topbox1").html();
								
								var mystr = "<b style='font-size:11px'>" + json.title + "</b><p style='margin:8px 0 0 0;padding:0;text-align:left;font-size:10px'>";
								
								if (json.year) {
									if ( clang == "gr")
										mystr += "Έτος ";
									else
										mystr += "Year ";
										
									mystr += json.year + "<BR>";
								}
								
								if (json.sizem2) {								
									if ( clang == "gr")
										mystr += "Επιφάνεια ";
									else
										mystr += "Size ";
										
									mystr += json.sizem2;
								
									if ( clang == "gr")
										mystr += " τμ<BR>";
									else
										mystr += " m2<BR>";
								}
								
								if (json.location) {
									if ( clang == "gr")
										mystr += "Περιοχή ";
									else
										mystr += "Location ";
										
									mystr += json.location;
								}
								
								
								mystr += "<BR><BR>"+json.details+"</p>";
								$("#pr_desc").html(mystr);
						});
						
						
						
			$.getJSON("ajax_get_project_photos.php?pid=" + pid, 
						function(json){
						
							product_images = [];
							product_images_filenames = [];
							product_images_loaded = [];
							product_index = 0;
							
							
							$.each(json.items, function(i,item){
							
								 //$('<img />').attr('src', '/phpthumb/phpThumb.php?src=/imported/products/' + item.filename);
								product_images_loaded[i] = 0;
								product_images_filenames[i] = item.filename;
								product_images[i] = $('<img />')
															    .attr('src', '/phpthumb/phpThumb.php?src=/imported/products/' + item.filename+'&h=430')
															    .load(function(){
																product_images_loaded[i] = 1;
																//alert(i+ " loaded");
															        //$('.profile').append( $(this) );
															        // Your other custom code
															    });
	

								//product_images.push(item.filename);
							});
							
							$("#pr_bigback").css("background-color", "#000");
							$("#pr_arrow_left_slide").fadeIn();
							$("#pr_arrow_right_slide").fadeIn();
							$("#pr_zoom").fadeIn();
							setTimeout(function() { show_loading()}, 100); 	
							showSliderImage(0);
							//tim = setTimeout(function() { showNextPic()}, 5000); 	

						});
	}
	



	
	
	
	$('.pcategory').click (function() {
	
		var cid_clicked = parseInt($(this).attr('rel'));
		
		$("#topbox2").html("");
		$("#topbox1").html("");
		$("#pr_arrow_left").fadeIn();
		$("#pr_arrow_right").fadeIn();
		$('.pcategory').css("color", "#bbb");
		$(this).css("color", "#3c8097");
		

		
					
		$.getJSON("ajaxproducts_slide.php?cid=" + cid_clicked, 
					function(json){
					
						$('#pr_slideshow_content').html(json.content);
						
						
						$('.slider_image').click (function() {
	
								
								var pid_clicked = parseInt($(this).attr('pid'));
								product_index = 0;
								slider_image_clicked (pid_clicked);
			
								$("#pr_slideshow_content div img").css("border", "0");
								$(this).css("border", "2px solid #eee");
			
								return false;
						});
	
					});
					
		return false;
	});
	
	if ($('.scroll-pane2').length) {
		var api = $('.scroll-pane2').jScrollPane(
		{
			showArrows:true,
			maintainPosition: false
		}
		).data('jsp');
	}

				
	$('.pcategory2').click (function() {
	
		var cid_clicked = parseInt($(this).attr('rel'));
		//.jScrollPane({scrollbarWidth:20, scrollbarMargin:10}
		//$("#pr_arrow_left").fadeIn();
		//$("#pr_arrow_right").fadeIn();
		$('.pcategory2').css("color", "#7a7a7a");
		$(this).css("color", "#3c8097");
		$("#top_level_2").show('slow');
					
		$.getJSON("ajaxproducts_slide2.php?cid=" + cid_clicked + "&lang="+clang, 
					function(json){
						

						api.getContentPane().html(json.content);	
						api.reinitialise();


	  
	  
						$('.slider_image').click (function() {
	
								
								var pid_clicked = parseInt($(this).attr('pid'));
								product_index = 0;
								slider_image_clicked (pid_clicked);
			
								$('.slider_image').css("color", "#7a7a7a");
								$(this).css("color", "#3c8097");
		
								//$("#pr_slideshow_content div img").css("border", "0");
								//$(this).css("border", "2px solid #eee");
			
								return false;
						});
	
					});
					
		return false;
	});
	
	
	
	$('.pnews2').click (function() {
	
		var cid_clicked = parseInt($(this).attr('rel'));
		//.jScrollPane({scrollbarWidth:20, scrollbarMargin:10}
		//$("#pr_arrow_left").fadeIn();
		//$("#pr_arrow_right").fadeIn();
		$('.pnews2').css("color", "#7a7a7a");
		$(this).css("color", "#3c8097");
		$("#top_level_2ext").show('slow');
					
		$.getJSON("ajaxnews2.php?id=" + cid_clicked + "&lang="+clang, 
					function(json){
						
						$('#top_level_2ext').html(json.text);
						
						if (json.filename){
						$('#content').fadeOut('fast', function() {
							$('#content').html("<img src='/imported/news/"+json.filename+"'>").fadeIn('slow');
						});
						}
						else
							$('#content').html('');
	
					});
					
		return false;
	});
	
	
	
		// initialize scrollable 
	$("#pr_slideshow").scrollable(); 
	
	
	function showNextPic () {
	
		product_index++;
		
		if (product_index >= product_images.length)
			product_index = 0;
		
		showSliderImage(product_index);
		//clearTimeout(tim);
		//tim = setTimeout(function() { showNextPic()}, 5000); 	
	}
	
	
	
	$("#pr_arrow_right_slide_img").click (function() {
		
		showNextPic();
		
	});
	
	$("#pr_arrow_left_slide_img").click (function() {
		
		product_index--;
		
		if (product_index == -1)
			product_index = product_images.length-1;
		
		showSliderImage(product_index);
		
	});
	
	
	$("#pr_zoom_img").click (function() {
		
		//e.preventDefault();
	    $.nyroModalManual({
	      url: '/imported/products/'+product_images_filenames[product_index]
	    });
	    return false;

		
	});
	
	
	function show_loading() {
	
		var loaded_cnt = 0;
		for (j=0;j<product_images_loaded.length;j++) {
			if (product_images_loaded[j] == 1)
				loaded_cnt++;
		}
		
		if (loaded_cnt == product_images_loaded.length)
			$("#pr_show_loading").html("");
		else {
			$("#pr_show_loading").html('loading ' + loaded_cnt + '/' +product_images_loaded.length+' photos');
			setTimeout(function() { show_loading()}, 1000); 
		}
		
	}
	
	
	
  } ); 
  
  
  
