var isExtended = 1;
var height = 850;
var width = 120;
var slideDuration = 1000;
var opacityDuration = 1500;


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function checkPosition()
{
string=getCookie('pozicija')
if (string!="1")	
{  	
  		isExtended = 0;
  		
  } else {
  		isExtended = 1;
  		
  }

}

function extendContract(){
	
	if(isExtended == 0){
		
		sideBarSlide(0, height, 1, width);
		
		sideBarOpacity(0, 1);
	
		isExtended = 1;
		
		
		// make expand tab arrow image face left (inwards)
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');
		
		ustvariPiskotek('pozicija','1','356');
	
	}
	else{
		
		sideBarSlide(height, 0, width, 0);
		
		sideBarOpacity(1, 0);
		
		isExtended = 0;
		
		
		// make expand tab arrow image face right (outwards)
		
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');
		
		ustvariPiskotek('pozicija','0','356');
	}

}

function sideBarSlide(fromHeight, toHeight, fromWidth, toWidth){
		var myEffects = new Fx.Styles('sideBarContents', {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'height': [fromHeight, toHeight],
			 'width': [fromWidth, toWidth]
		});
}

function sideBarOpacity(from, to){
		var myEffects = new Fx.Styles('sideBarContents', {duration: opacityDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'opacity': [from, to]
		});
}

function init(){
	$('sideBarTab').addEvent('click', function(){extendContract()});
}

function ustvariPiskotek(ime,vrednost,potece) {
	var date = new Date();
	date.setTime(date.getTime()+(potece*24*60*60*1));
	document.cookie = ime+"="+vrednost+"; expires="+date.toGMTString()+"; path=/";	
}	

window.addEvent('load', function(){init()});