
	function changeImageFromParent(uri,_this)
		{/*{{{*/
			if (!uri) return false;

			if (_this && _this.firstChild && _this.firstChild.tagName && _this.firstChild.tagName.toLowerCase) //DOM ?
				{
					if (_this.firstChild.tagName.toLowerCase() == 'img') // <img... ?
					_this.firstChild.src = uri;//set src="...">
					return true;
				}

			//IE 4+ (?)
			if (!window || !window.event || !window.event.srcElement || !window.event.srcElement.tagName) return false;
			if (window.event.srcElement.tagName.toLowerCase() != 'img') return false;
			window.event.srcElement.src = uri;
			return true;
		}/*}}}*/
	function changeImageFromSubmit(uri,_this)
		{/*{{{*/
			if (uri && _this && _this.src) _this.src = uri;
		}/*}}}*/
		
	
	function openProject(section,cat,file_id, id) {
		return (fillLayer(section,cat,file_id, id, 0));
	}
	
	function nextProject(section,cat,file_id, id) {
		return (fillLayer(section,cat,file_id, id, 1));
	}
	
	function prevProject(section,cat,file_id, id) {
		return (fillLayer(section,cat,file_id, id, -1));
	}
	
	function fillLayer(section,cat,file_id, id, pos) {
		pauseSlider();
		var tmpData=$('.boxCaption').data();
		$('.boxCaption').removeData();
		if($('.boxCaption .slider').size()) $('.boxCaption .slider').hide();
		
		var myDate		=	new Date();
		var url;
		
		switch(pos) {
			case -1:
				url = "/page/getpreviousproject/section/"+section+"/cat/"+cat+"/file_id/"+file_id+"/id/"+id+"/&t="+myDate.getMilliseconds();
				break;
			case 0:
				url = "/page/getproject/section/"+section+"/cat/"+cat+"/file_id/"+file_id+"/id/"+id+"/&t="+myDate.getMilliseconds();
				break;
			case 1:
				url = "/page/getnextproject/section/"+section+"/cat/"+cat+"/file_id/"+file_id+"/id/"+id+"/&t="+myDate.getMilliseconds();
				break;
			default:
				url = "/page/getproject/section/"+section+"/cat/"+cat+"/file_id/"+file_id+"/id/"+id+"/&t="+myDate.getMilliseconds();
				break;
		}
		
		 $.ajax({
		 	type:			"GET",
		 	cache:			"false",
		 	url:			url,
		 	contentType:            "application/json; charset=utf-8",
			dataType:		"json",
			success: function(data) {
				if(!data.length) {
					if(!$.isEmptyObject(tmpData)) $('.boxCaption .slider').data(tmpData).show();
					return false;
				}
				for (i=0; i<data.length; i++) {
		 			var gallery;
		 			
		 			var prevImg			=	new Object;
		 				prevImg.file_id         =	data[0].file_id;
		 				prevImg.id		=	data[0].id;
		 				prevImg.first           =	true;
		 			var nextImg			=	new Object;
		 				nextImg.file_id         =	data[0].file_id;
		 				nextImg.id		=	data[0].id;
		 				nextImg.last            =	true;

		 				if (i>0) {
		 					prevImg.file_id	=	data[i-1].file_id;
		 					prevImg.id	=	data[i-1].id;
		 					prevImg.first	=	false;
		 				}
		 				
		 				if (i<data.length-1) {
		 					nextImg.file_id	=	data[i+1].file_id;
		 					nextImg.id	=	data[i+1].id;
		 					nextImg.last	=	false;
		 				}

		 			
		 			if (i==0) {
		 				var ev=data[i].embed_video,insert=ev==null||ev==''?'<img src="/prev/929x652'+data[i].full_path+data[i].full_file+'" id="bigImg'+data[i].id+'" />':$(ev);
						$('#bigImage').html(insert);
		 				$('#projectTitle').html(data[i].title);
		 				$('#projectTitle').hide();
						
		 				infos = new Array();
		 				$('dl.default_02 > dt').each(function(){infos[infos.length] = this.className;});

		 				for (j=0; j<infos.length; j++) {
		 					if ($('dd.'+infos[j]).size()) {

		 						if (data[i][infos[j]]) {
			 						$('dd.'+infos[j]).html(data[i][infos[j]]);
			 						$('.'+infos[j]).show();
			 					} else {
			 						$('dd.'+infos[j]).html("&nbsp;");
			 						$('.'+infos[j]).hide();
			 					}
			 				}
		 				}
				 		
				 		if (i>0) {
				 			$('#prevProject').html('<a href="#" onclick="return updateLayer(\''+section+'\',\''+cat+'\',\''+data[i-1].file_id+'\',\''+data[i-1].id+'\');" class="invertPrevButton"><span>Previous</span></a>');
				 		} else {
				 			$('#prevProject').html('<a href="#" onclick="return prevProject(\''+section+'\',\''+cat+'\',\''+data[i].file_id+'\',\''+data[i].id+'\');" class="invertPrevButton"><span>Previous</span></a>');
				 		}
				 		
				 		if (i < data.length-1) {
				 			$('#nextProject').html('<a href="#" onclick="return updateLayer(\''+section+'\',\''+cat+'\',\''+data[i+1].file_id+'\',\''+data[i+1].id+'\');" class="invertNextButton"><span>Next</span></a>');
				 		} else {
				 			$('#nextProject').html('<a href="#" onclick="return nextProject(\''+section+'\',\''+cat+'\',\''+data[i].file_id+'\',\''+data[i].id+'\');" class="invertNextButton"><span>Next</span></a>');
						}
						
						gallery = '<a href="#" onclick="updateLayer(\''+section+'\',\''+cat+'\',\''+data[i].file_id+'\',\''+data[i].id+'\');" class="prevIcon active" id="thumbnail'+data[i].id+'" rel="'+prevImg.file_id+'|'+prevImg.id+'|'+prevImg.first+'" ref="'+nextImg.file_id+'|'+nextImg.id+'|'+nextImg.last+'">&nbsp;</a>';
						
		 			} else {
		 				gallery += '<div class="whiteSpace">&nbsp;</div>';
	 					gallery += '<a href="#" onclick="updateLayer(\''+section+'\',\''+cat+'\',\''+data[i].file_id+'\',\''+data[i].id+'\');" class="prevIcon" id="thumbnail'+data[i].id+'" rel="'+prevImg.file_id+'|'+prevImg.id+'|'+prevImg.first+'" ref="'+nextImg.file_id+'|'+nextImg.id+'|'+nextImg.last+'">&nbsp;</a>';
		 			}
		 			$('#gallery').html(gallery);
					
					if(data[i]['slideshow']) prepareSliderImages(data,i);
					
		 		}
		 		$('#modalContent').fadeIn("fast");
				
				initSlider(data[0].id);
		 	}
		 });
		 
		 return false;
	}
	
	function updateLayer(section,cat,file_id, id) {
		
		if($('.boxCaption .slider').size()) { $('.boxCaption .slider').hide();pauseSlider(); }
		var myDate	=	new Date();
		
	    var url = "/page/getobject/section/"+section+"/cat/"+cat+"/file_id/"+file_id+"/id/"+id+"/&t="+myDate.getMilliseconds();
	    
		$('#bigImage > img').fadeOut("fast");
		//$('#projectTitle').fadeOut("fast");
		$('#projectTitle').hide();
		$('dl.default_02').fadeOut("fast");
		
		$.ajax({
		 	type:			"GET",
		 	cache:			"false",
		 	url:			url,
		 	contentType:	"application/json; charset=utf-8",
			dataType:		"json",
			success: function(data) {
				
				initSlider(data.id);
				
				$('#projectTitle').html(data.title);
				
				thumbnail	=	$('#thumbnail'+id);
				prevInfos	=	thumbnail.attr("rel").split("|");
				nextInfos	=	thumbnail.attr("ref").split("|");
				
				$('#gallery a').removeClass('active');
				thumbnail.addClass('active');
				
				if (prevInfos[2]=='false') {
					$('#prevProject').html('<a href="#" onclick="return updateLayer(\''+section+'\',\''+cat+'\',\''+prevInfos[0]+'\',\''+prevInfos[1]+'\');" class="invertPrevButton"><span>Previous</span></a>');
				} else {
					$('#prevProject').html('<a href="#" onclick="return prevProject(\''+section+'\',\''+cat+'\',\''+file_id+'\',\''+id+'\');" class="invertPrevButton"><span>Previous</span></a>');
				}
				
				if (nextInfos[2]=='false') {
					$('#nextProject').html('<a href="#" onclick="return updateLayer(\''+section+'\',\''+cat+'\',\''+nextInfos[0]+'\',\''+nextInfos[1]+'\');" class="invertNextButton"><span>Next</span></a>');
				} else {
					$('#nextProject').html('<a href="#" onclick="return nextProject(\''+section+'\',\''+cat+'\',\''+nextInfos[0]+'\',\''+nextInfos[1]+'\');" class="invertNextButton"><span>Next</span></a>');
				}
				
				var ev=data.embed_video,insert=ev==null||ev==''?'<img src="/prev/929x652'+data.full_path+data.full_file+'" />':$(ev);
				$('#bigImage').html(insert);
 				
 				infos = new Array();
		 		$('dl.default_02 > dt').each(function(){infos[infos.length] = this.className;});

 				for (j=0; j<infos.length; j++) {
 					if ($('dd.'+infos[j]).size()) {
	 					if (data[infos[j]]) {
	 						$('dd.'+infos[j]).html(data[infos[j]]);
	 						$('.'+infos[j]).show();
	 					} else {
	 						$('dd.'+infos[j]).html("&nbsp;");
	 						$('.'+infos[j]).hide();
	 					}
	 				}
 				}
				
 				$('#bigImage > img').fadeIn("fast");
 				//$('#projectTitle').fadeIn("fast");
  				$('dl.default_02').fadeIn("fast");
				
		 	}
		 });

		 return false;
	}
	
	function resetSlider(r) {if (!$('#oldImage').size()){$('.containerImg').prepend('<table class="detailImage old" cellspacing="0" cellpadding="0"><tr><td id="oldImage"></td></tr></table>');}else {if(r) $('#oldImage > img').remove();}}
	function prepareSliderImages(data,i) {var sl = new Array();sl[0] = new Image();sl[0].src = '/prev/929x652'+data[i]['full_path']+data[i]['full_file'];for (var j=0;j<data[i]['slideshow'].length;j++){sl[j+1] = new Image();sl[j+1].src = '/prev/929x652'+data[i]['slideshow'][j]['full_path']+data[i]['slideshow'][j]['full_file'];}$('.boxCaption').data(data[i].id,{'slideshow':sl});}
	function initSliderControls() {var sl = $('.boxCaption .slider');if (sl.size()) {sl.find('.slLeft').click( function() {moveSlider(0);});sl.find('.slRight').click( function() {moveSlider(1);});sl.find('.slPlay').click( function() {if ($(this).hasClass('pause')) {pauseSlider();}else{$(this).addClass('pause');playSlider(1);}});}}
	function initSlider(id) {resetSlider(1);var sl = $('.boxCaption').data(id);if (sl) {sl=sl['slideshow'];$('.boxCaption .slider').show();pauseSlider();$('.slArea').slider('destroy');$('.slArea').slider({min:0,max:sl.length-1,value:0,change:function(event,ui){fadeSlider(sl,ui.value);},slide:function(event,ui){pauseSlider();fadeSlider(sl,ui.value);}});}}
	function playSlider() {moveSlider(1,1);$('.boxCaption').data('tmr',setTimeout("playSlider(1);",2000));}
	function pauseSlider() {var tmr=$('.boxCaption').data('tmr');if(!tmr)return;clearTimeout(tmr);$('.boxCaption').data('tmr','');$('.boxCaption .slPlay').removeClass('pause');}
	function moveSlider(d,a) {if(!a)pauseSlider();var s = $('.slArea').slider('option','value') + (d?1:-1);d?$('.slArea').slider('option','value',s>$('.slArea').slider('option','max')?0:s):$('.slArea').slider('option','value',s<0?$('.slArea').slider('option','max'):s);}
	function fadeSlider(sl,pos) {resetSlider();$('#oldImage').html($('#bigImage > img').stop().fadeTo(0,1));$('#modalContent #bigImage').html($(sl[pos]).hide().clone()).find('img').fadeTo(400,1);}
	
	// initialise plugins
	jQuery(document).ready(function() { 
		$('ul.sub_menu').superfish();
		

		/*$('.gateLayer')
			.click(function() {
				$('#modalContent').show();
			});
		*/
			
		$('.closeButton')
			.click(function() {
				$('#modalContent').fadeOut("fast");pauseSlider();
			});	
			
			
		jQuery(function() {
		   jQuery('#slideshow1').cycle({
		   	timeout:7000,
		   	width:684,
		   	height:487,
                        next:   '#next2',
                        prev:   '#prev2'
		   });
		   jQuery('#slideshow2').cycle({
		   	timeout:7000,
		   	cleartype:  1,
                        next:   '#next2',
                        prev:   '#prev2'
		   });
		    
		});	
		
		initSliderControls();
		
		$(document).keyup(function(e){if(e.keyCode==27&&$('#modalContent:visible').size())$('.closeButton').trigger('click');});
	});
	
	$('html').live('click',function(e){var n=e.target.nodeName;if($('#modalContent:visible').size()&&(n=='HTML'||n=='BODY'))$('.closeButton').trigger('click');});
	
