//Get URL Params
function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
}

//Show/ Hide client list
function showhide(clients){
	if (document.getElementById){
		obj = document.getElementById(clients);
		if (obj.style.display == "none"){
			obj.style.display = "";
		} else {
			obj.style.display = "none";
		}
	}
}

//Ajax+menu+portofoliu nav
var menuopen = (gup("am")!=null)?gup("am"):0;
var pgopen = (gup("ap")!=null)?gup("ap"):0;
var dest = [];
var lastpg = [];
window.addEvent('domready', function(){

	var szNormal = 36, szSmall  = 36; szFull = 36;
		
	//selecteaza toate elementele #sidemenu .ext
	var kwicks = $$("#sidemenu .ext");
	var fx = new Fx.Elements(kwicks, {wait: false, duration: 500, transition: Fx.Transitions.Back.easeOut});
	kwicks.each(function(kwick, i) {
		//event - deschide meniurile la click
		kwick.addEvent("mouseclick", function(event) {
			var k = 0;
			var zzz = $$(".inline");
			zzz.each(function(zzz, p) {
				if (zzz.parentNode.parentNode == kwick)
					k++;
			});
			var o = {};
			o[i] = {height: [kwick.getStyle("height").toInt(),65]}
			kwicks.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle("height").toInt();
					if(w != szSmall) o[j] = {height: [w, szSmall]};
				}
			});
			fx.start(o);
			menuopen = i;
			var kiwi = $$("#sidemenu .ext");
			//seteaza clasa ext selected pentru meniul deschis, ext pentru cele inchise
			kiwi.each(function(kiwi, p) {
				if (p == menuopen){
					kiwi.className = "ext selected";
				}
				else{
					kiwi.className = "ext";
				}
			});
			//da comanda sa se incarce prima lucrare din meniu
			new Ajax( dest[menuopen][0], {
				method: 'get',
				update: $('inc')
			}).request();
			pgopen = 0;
		});
	
		//pentru fiecare buton din meniu pune functiile de click
		var ajx = $$(".ajax");
		var tpm = 0;
		var tdest = [];
		ajx.each(function(ajx, m) {
			if (ajx.parentNode.parentNode.parentNode == kwick){
				tpm++;
				//event - click pe butoanele din meniul deschis
				ajx.addEvent('mouseclick', function(e) {
					e = new Event(e).stop();
					pgopen = ajx.name.toInt();
					new Ajax( ajx.href, {
						method: 'get',
						update: $('inc')
					}).request();
				});
				tdest[tpm-1]=ajx.href;
				
				// !!! deschide prima lucrare care se afiseaza cand se incarca pagina de portofoliu
				if (((tpm-1)==pgopen) && (menuopen==i)){
					new Ajax( ajx.href, {
						method: 'get',
						update: $('inc')
					}).request();
				}
				lastpg[i] = tpm-1;
			}
		});
		dest[i]=tdest;

		//deschide meniul default sau din getURL
		//pune clasa la meniul deschis ext selected
		if (i == menuopen) {
			kwicks[i].className = "ext selected";
			var items = $$(".inline");
			var itm = 0;
			items.each(function(items, n) {
				if (items.parentNode.parentNode == kwicks[i])
					itm++;
			});
			kwicks[i].style.height = (itm*20+65)+"px";
		}
	});
}); 

function goLeft(e){
    leftx = document.getElementById('innercontent');
    lefty = document.getElementById('scroller2');
    x = leftx.style.left.toInt();
    y = lefty.style.left.toInt();
 	if(x == "" || isNaN(x)){
 		x = 0;
   	}
 	if(y == "" || isNaN(y)){
 		y = 0;
   	}
	var a = x + 580; 

	if (x < 0 && a%580==0)
	{
	   	$('innercontent').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(x, x + 580 );
	   	$('scroller2').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(y, y + 340 );
	}
	else{
		x = -580 * e;
		y = -340 * e;
	   	$('innercontent').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(x, x + 580 );
	   	$('scroller2').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(y, y + 340 );
	}
}

function goRight(e){
   	rightx = document.getElementById('innercontent');
    righty = document.getElementById('scroller2');
   	x = rightx.style.left.toInt();
   	y = righty.style.left.toInt();
   	if(x == "" || isNaN(x)){
   		x = 0;
   	}
   	if(y == "" || isNaN(y)){
   		y = 0;
   	}
	var a = x - 580; 
	var b = e * -580;
	if (a > b && a%580==0)
	{
		$('innercontent').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(x, x - 580 );
		$('scroller2').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(y, y - 340 );
	}
	else{
		x = 580;
		y = 340;
	   	$('innercontent').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(x, x - 580 );
	   	$('scroller2').effect('left',{ duration: 400, transition: Fx.Transitions.Quad.easeIn, wait:true }).start(y, y - 340 );
	}
}