var $_GET=Array()
$chunks=window.location.href.split("/");
for($x=0; $x<$chunks.length; $x++){
	if($chunks[$x].search("_")){
		$parts=$chunks[$x].split("_");
		$_GET[$parts[0]]=$parts[1];
	}
}

function amILocal($needle){
	$haystack=window.location.href;
	if($haystack.search($needle)>=0){
		return true;
	} else {
		return false;
	}
}

if(amILocal(LOCAL_HOST)){
	ROOT="http://"+LOCAL_HOST+"/"+LOCAL_FOLDER+"/";
	AJAXURLstop=LOCAL_FOLDER;
} else {
	ROOT="http://"+LIVE_URL+"/";
	AJAXURLstop=LIVE_URL;
}

function createCookie(name,value,days) {
	if(days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

URLparts=window.location.href.split("/");
addParts=true;
AJAXlink="";
for(i=URLparts.length-2; i>0; i--){
	if(URLparts[i]==AJAXURLstop){
		addParts=false;
	}
	if(addParts){
		AJAXlink+="../";
	}
}
AJAXlink+="ajax/";

window.addEvent("domready", function(){

    $$("#cats li a").each(function(el){
      el.container=el.getParent();
      el.container.setStyle("height", 20);
      $(el.container.childNodes[0]).setStyle("opacity", 0);
      el.effect=new Fx.Styles(el.container, {duration:1000, wait:false});
      el.effect2=new Fx.Styles(el.container.childNodes[0], {duration:1000, wait:false});
      el.onmouseover=function(){
        this.effect.start({
          height:this.container.getSize().scrollSize.y
        });
        this.effect2.start({
          opacity:1
        });
      };
      el.onmouseout=function(){
        this.effect.start({
          height:20
        });
        this.effect2.start({
          opacity:0
        });
      };
    });

    $$("#diy li a").each(function(el){
      el.container=el.getParent();
      el.container.setStyle("height", 20);

      el.img = $ES('img', el.container);
      el.img[0].setStyle("opacity", 0);

      el.effect=new Fx.Styles(el.container, {duration:1000, wait:false});
      el.effect2=new Fx.Styles(el.img[0], {duration:1000, wait:false});
      el.onmouseover=function(){
        this.effect.start({
          height:this.container.getSize().scrollSize.y
        });
        this.effect2.start({
          opacity:1
        });
      };
      el.onmouseout=function(){
        this.effect.start({
          height:20
        });
        this.effect2.start({
          opacity:0
        });
      };
    });
});


var numpics=-1;
var piccount=1;

window.onload=function(){
	$$("#header img").each(function(element){
    element.setStyle("opacity", 0);
    element.fader=new Fx.Styles(element, {duration:4000, onComplete:function(){nextFader()}});
  });
  numpics=$$("#header img").length-1;
	$$("#header img")[0].setStyle("opacity", 1);
	$$("#header img")[1].fader.start({opacity:[0,1]});
}

function nextFader(){
  if(piccount=="RESTART"){
    piccount=1;
    $$("#header img")[piccount].fader.start({opacity:[0,1]});
  } else if(piccount==numpics){
  	$$("#header img").each(function(element, index){
      if(index!=0 && index!=numpics){
        element.setStyle("opacity", 0);
      }
    })
    piccount="RESTART";
    $$("#header img")[numpics].fader.start({opacity:[1,0]});
  } else {
    piccount++;
    $$("#header img")[piccount].fader.start({opacity:[0,1]});
  }
}
