// - crypt functions -----------------------------	
// http://www.toulouse-renaissance.net/c_outils/c_mailto_spam.htm
function Crypt(s) 
{
	r='';
	for(i=0;i<s.length;i++)
	{
		n=s.charCodeAt(i); 
		if (n>=8364) 
			{n = 128;} 
			r += String.fromCharCode( n - 3 ); 
	}
	return r;
}

function mt (name)
{
	var a  ="pdlowr=";
	var m ='&#64;';
	var d =unescape(m);
	var domaine = "atracsys.com";
	var aro = name + d + domaine;
	document.write('<a href='+ Crypt(a) + aro + '>');
	document.write(aro + '</a>');
}
// -----------------------------------------------	


function isSelected (item) {
	if (item.attr('class').indexOf('selected') == -1) 
		return false;
	else return true;
}

$("document").ready (function () {
	
	
	$("#logo_over").css ({opacity:0});
	$("#branding").mouseover (function() {		
		$("#logo_over").stop(true, true).fadeTo ('normal', 1);		
	})
	$("#branding").mouseout (function() {
		$("#logo_over").stop(true, true).fadeTo ('slow', 0);
	})
	

	$('.mainbtn').each (function () {
		t = $(this);
		if (!isSelected(t)) {
			t.css ('opacity', 0.9);
		}
		t.mouseover (function () {$(this).stop(true, true).fadeTo ('fast', 1)})
		t.mouseout (function () {
			if (!isSelected($(this)))
				$(this).stop(true, true).fadeTo ('slow', 0.9)})
	})

	
	$('.colorBtn, .btnplus').each (function () {
		t = $(this);
		if (!isSelected(t)) {
			t.css ('opacity', 0.8);
		}
		t.mouseover (function () {$(this).stop(true, true).fadeTo ('fast', 1)})
		t.mouseout (function () {
			if (!isSelected($(this)))
				$(this).stop(true, true).fadeTo ('slow', 0.8)})
	})
	
	$('.logo, li>a, .related_item').each (function () {
		
		t = $(this);
		if (!isSelected(t)) {
			t.css ('opacity', 0.6);
		}
		t.mouseover (function () {$(this).stop(true, true).fadeTo ('fast', 1)})
		t.mouseout (function () {
			if (!isSelected($(this)))
				$(this).stop(true, true).fadeTo ('slow', 0.6)})
	})
	
	
	$('input, select, textarea').focus (function () {
			$(this).stop(true, true).fadeTo ('fast', 1);
	})
	$("input, select, textarea").focusout (function () {
			$(this).stop(true, true).fadeTo ('fast', 0.7);
	})
	
	$('input, textarea, select, button').each (function () {
		
		t = $(this);
		t.css ('opacity', 0.7);
		t.mouseover (function () {$(this).stop(true, true).fadeTo ('fast', 1) 

		})
		t.mouseout (function () {$(this).stop(true, true).fadeTo ('slow', 0.7)})
	})
		
	
	
	$('.list_item').each (function () {
			var el = $(this);
			t = el.find ('img');
			
			var title = el.find ('.item_title');
			t.css ('opacity', 0.8);
			
			title.css ('opacity', 0.8);
			
			function mOver (event) {
				$(this).stop(true, true).fadeTo ('fast', 1)
				$(event.data.title).stop (true, true).fadeTo ('fast', 1);
			}
			
			function mOut (event) {
				$(this).stop(true, true).fadeTo ('slow', 0.8)
				$(event.data.title).stop (true, true).fadeTo ('slow', 0.8);
			}
			
			// with the bind method, we can pass some argument to the handler function
			// the arguments will be properties of the event.data var
			t.bind ('mouseover', {title:title}, mOver); 
			t.bind ('mouseout', {title:title}, mOut); 
			
	})
	
	

	// Flash messages
	// fadeout flash messages on click
	$('.flashClose').click(function(){
		$(this).parent().fadeOut();
	return false;
	});
	


	// $(".logo").each (function () {
	// 	logo = $(this);
	// 	logo.css ('opacity', 0.5);
	// 	logo.mouseover (function () {$(this).stop(true, true).fadeTo ('fast', 1)})
	// 	logo.mouseout (function () {$(this).stop(true, true).fadeTo ('slow', 0.5)})
	// 	
	// })
	
});




jQuery.createGalleries = function () {

	var galleries = [];

	$prev = "<img src='"+$webroot+"img/interface/prev.png' />";
	$next = "<img src='"+$webroot+"img/interface/next.png' />";
	$play = "<img src='"+$webroot+"img/interface/play.png' />";
					
	$("a").each (function () {
		$rel = $(this).attr('rel');
		
		
		if ($rel.indexOf ('gallery') != -1) {
			$slug = $rel.replace ('gallery', '');
			$slug = $slug.replace (' ', '');
			
			
			if (galleries [$slug] == null) {
				
				
				// build the navigation DOM elements

				$(this).before ("<a href='#' onclick='return false'><span id='counter_"	+$slug+"'>Images (1 / --)</span></a><div class='navigation'><b /><br /><a href='' onclick='return false' id='prev_"+$slug+"'>"+$prev+"</a> &nbsp;<a href='' id='next_"+$slug+"' onclick='return false;'>"+$next+"</a>")
				galleries [$slug] = new Gallery ($slug, $("#"+$slug+"_img"));
				//$(this).html (" ");
			
			}
		
			galleries [$slug].addImage ($(this).attr('href'));
			
			//$(this).fadeOut ();
			//$(this).changeColors ();
			$(this).remove ();
		}
		
	})
	
	$('.separator').remove ();	
}


