// JavaScript Document
// Author Christophe Iaïchouchen AKA saturnino pour Alambik Design
// Copyright : Culture(s) en chantier

// prévention des frames
if (top.frames.length!=0) top.location=self.document.location; 

jQuery.noConflict();


function getNews(permalink, li, parent,  height)
{
	jQuery.get("get-new-content.php", { news: permalink },function(data){
	
		parent.remove();
		parent = jQuery(data).appendTo(li);
		li.css('opacity',0.5);		
		
		var new_height = li.css('height');
		li.css('height',height);
		
		li.animate({
			opacity: 1,
			height:new_height
		  }, 500, function() {
			// Animation complete.			
		  });	
		
	 });
}

function initNews()
{
	jQuery('#news a.follow').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');			
			
			if (link.indexOf('=') > -1)
			{
				var s 		= link.split('=');
				var parent 	= jQuery(this).parent();
				var li 		= jQuery(this).parent().parent();
				var height  = parent.css('height');		
				
				jQuery(this).remove();
				
				li.animate({
					opacity: 0.5
					/*height: 'toggle'*/
				  }, 200, function() {
					// Animation complete.					
					getNews(s[1], li, parent, height);
				  });	
			}
	});			
}

// gestion des liens externes
function initExternalLinks()
{
	jQuery('a[class=external]').attr('target', '_blank');
}


function initAnchors()
{

	jQuery('.anchorTop a').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');			
			
			if (link.indexOf('#') > -1)
			{
				var s 		= link.split('#');
				if(s.length==2 && document.getElementById(s[1]) )
				{
					jQuery.scrollTo( '#'+s[1], 800, {easing:'easeout'} );
				}	
			}
	});		
}

function initSifr()
{
	var ger4ronl = {
		src: siteurl+'/swf/ger4ronl.swf'
		,ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16]
	  };
	
	//sIFR.domains = ['culturesenchantier.com']; // Don't check for domains in this demo
	//sIFR.useStyleCheck = true;
	sIFR.activate(ger4ronl);


	sIFR.replace(ger4ronl, {
			selector: 'h2.ger4ronl'
			,wmode: 'transparent'
			,css: { '.sIFR-root' : {'color': '#01916e', 'font-size':'20','padding-top':'10','margin-top':'10','line-height':'12','leading':'10'} }

				 }
	);

}
initSifr();

function showWorks(id)
{
	for(i = 0; i< works.length ; i++)
	{
		if( id == works[i] || id == i )
		{
			//jQuery("#"+works[i]).show();
			jQuery("#workcategory-"+works[i]).addClass('active');
			jQuery("#"+works[i]).slideDown("slow",function(){ //alert("Animation Done.");
																	  });
		}else{
			//jQuery("#"+works[i]).hide();
			jQuery("#workcategory-"+works[i]).removeClass('active');
			jQuery("#"+works[i]).slideUp("fast",function(){ //alert("Animation Done."); 
																  });
		}
	}
}

works = Array();
function initWorks()
{
	jQuery('#left-nav li a').each(function(i){			
					
			var link = jQuery(this).attr('href');			
			
			if (link.indexOf('#') > -1)
			{
				var s 		= link.split('#');
				if(s.length==2 && document.getElementById(s[1]) )
				{
					jQuery("#"+s[1]).hide();
					works[i] = s[1];
				}	
			}
	});	

	
	jQuery('#left-nav li a').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');			
					
			if (link.indexOf('#') > -1)
			{
				var s 		= link.split('#');
				if(s.length==2 && document.getElementById(s[1]) )
				{
					showWorks(s[1]);					
				}	
			}
	});		
	
	showWorks(0);
}

function popupCredit(theURL,winName,largeur,features)
{ 
	if(! window.focus){  return; }
	var left = 'left='+(screen.width-largeur-100);
	var credit = window.open(theURL,winName,left+','+features);
	credit.focus();
	theURL.target = winName;		
}


jQuery(document).ready(function(){

	initNews();
	
	initAnchors();	
	
	initWorks();
	
	initExternalLinks();
	
	if(document.getElementById('contactForm') )
	{
		var myForm = jQuery("#contactForm");    
		myForm.validation();
	}
	
	jQuery("#top-nav").lavaLamp({ fx: "backout", speed: 700});
	
	jQuery('a[class=mentions]').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');	
			popupCredit(link,'credits','350','height=650,width=350,top=10,scrollbars=no,status=no,menubar=no,resizable=no');
					
			
	});	
 
});

