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/";

var Accordions=Array();

function show(whichOne){
	if(whichOne == 1){
		tDiv = "div";
		vDiv = "divs";
	}else{
		tDiv = "divs";
		vDiv = "div";
	}
	if($(tDiv).fx){$(tDiv).fx.stop();}
	if($(vDiv).fx){$(vDiv).fx.stop();}
	$(tDiv).fx = $(tDiv).effect('opacity', {duration: 2000}).start(0);
    $(vDiv).setStyle('display','block');
	$(vDiv).fx = $(vDiv).effect('opacity', {duration: 2000}).start(1);
}
function showMiddle(start){
    var finish;
    var starts;
    var tDiv;
    var vDiv;
    var number;
    switch (start){
          case 1:
          starts = "imgone";
          finish = "imgtwo";
          number = 1;
          break;
          case 2:
          starts = "imgtwo";
          finish = "imgthree";
          number = 2;
          break;
          case 3:
          starts = "imgthree";
          finish = "imgfour";
          number = 3;
          break;
          case 4:
          starts = "imgfour";
          finish = "imgfive";
          number = 4;
          break;
          case 5:
          starts = "imgfive";
          finish = "imgsix";
          number = 5;
          break;
          case 6:
          starts = "imgsix";
          finish = "imgseven";
          number = 6;
          break;
          case 7:
          starts = "imgseven";
          finish = "imgone";
          number = 7;
          break;
          }
        tDiv = starts;
		vDiv = finish;
   if (number <= '7')
   {
	if($(tDiv).fx){$(tDiv).fx.stop();}
	if($(vDiv).fx){$(vDiv).fx.stop();}
	$(tDiv).fx = $(tDiv).effect('opacity', {duration: 300}).start(0);
    $(vDiv).setStyle('display','block');
	$(vDiv).fx = $(vDiv).effect('opacity', {duration: 300}).start(1)
    if (number != 7 ){
        var newnumber = number +1;
        var myFunction = function() { showMiddle(newnumber); };
        myFunction.delay(5000);

    }
    else
    {
      newnumber = 1;
       var myFunction = function() { showMiddle(newnumber); };
        myFunction.delay(5000);
    }
   }
}

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

    $$("#contactdetails2 ul li h1 a.contactlink").each(function(element){
        whichNode=window.ie?1:3
        if(element.details=element.getParent().getParent().childNodes[whichNode]){
            element.details.slide=new Fx.Styles(element.details, {duration:1000, wait:false});
            element.details.slide.open=false;
            element.details.setStyles({
				opacity:0,
				height:0
			});
		   if (element.id==$_GET['read']){
             //this is to open up the link to whatever page you are currently on so the menu stays open
           /*element.details.slide.start({
                    "height": element.details.getSize().scrollSize.y-1,
                    marginBottom: 10,
                    opacity:.8
                });
                element.details.slide.open=true; */
           }
            element.onclick=function(){
                element.blur();
                if(!this.details.slide.open){
                    this.details.slide.start({
                        "height": this.details.getSize().scrollSize.y-1,
                        marginBottom: 10,
                        opacity:1
                    });
                    this.details.slide.open=true;
                    this.setStyle("background-image", "url(images/framework/address_up.png)");

                } else {
                    this.details.slide.start({
                        "height": 0,
                        marginBottom: 0,
                        opacity:0
                    });
                    this.details.slide.open=false;
                    this.setStyle("background-image", "url(images/framework/address_down.png)");
                }
                //$(this.childNodes[0]).setStyle("height", "auto");
                return false;
            }
        }
    });

    $$("#contactdetails2 ul li h1 a div a").each(function(element){
        parts=element.href.split("/");
        for(i=0; i<parts.length; i++){
            values=parts[i].split("_");
            if(values[0]=="read" && values[1]==$_GET['read']){
                element.className="active";
            }
        }
    });
	$$("#column1 ul#mainmenu li a").each(function(element){
        if(element.subMenu=element.getParent().childNodes[2]){
            element.subMenu.slide=new Fx.Styles(element.subMenu, {duration:1000, wait:false});
            element.subMenu.slide.open=false;
           
            element.subMenu.setStyles({
        	opacity: 0,
        	height:0,
        	marginBottom:0
        });
              if(element.id==$_GET['menu']){

                element.subMenu.slide.start({
                    "height": element.subMenu.getSize().scrollSize.y-1,
                    marginBottom: 10,
                    opacity:.8
                });
                element.subMenu.slide.open=true;
                element.setStyle("background-image", "url(images/framework/menu_up1.png)");

            }

            element.href="javascript:void(0)";
            element.onclick=function(){

                element.blur();
                if (($(this).id=='ruralservices') && (this.subMenu.slide.open!=true)){
                    this.subMenu.slide.open=true;

                    window.location=ROOT+'menu_ruralservices/page_show/read_ruralprofessional/index.html';

                }
                if (($(this).id=='lettingsmenu') && (this.subMenu.slide.open!=true)){
                    this.subMenu.slide.open=true;
                    window.location=ROOT+'menu_lettingsmenu/page_show/read_lettingsintro/index.html';

                }
                if (($(this).id=='renewable') && (this.subMenu.slide.open!=true)){
                    this.subMenu.slide.open=true;
                    window.location=ROOT+'menu_renewable/page_show/read_renewable/index.html';

                }
                if (($(this).id=='auctionsmenu') && (this.subMenu.slide.open!=true)){
                    this.subMenu.slide.open=true;
                    window.location=ROOT+'menu_auctionsmenu/page_show/read_auctionintro/index.html';

                }
                if(!this.subMenu.slide.open){
                    this.subMenu.slide.start({
                        "height": this.subMenu.getSize().scrollSize.y-1,
                        marginBottom: 10,
                        opacity:.8
                    });

                    this.subMenu.slide.open=true;
                    this.setStyle("background-image", "url(images/framework/menu_up1.png)");
             if(element.subMenu=element.getParent().childNodes[2]){
                    element.addClass('selected');
                    }
                } else {
                    this.subMenu.slide.start({
                        "height": 0,
                        marginBottom: 0,
                        opacity:0
                    });
                    this.subMenu.slide.open=false;
                    this.setStyle("background-image", "url(images/framework/menu_down.png)");
                }
                //$(this.childNodes[0]).setStyle("height", "auto");
                return false;

            }
        }


    });

    $$("#column1 ul#mainmenu li ul li a").each(function(element){
        parts=element.href.split("/");
        for(i=0; i<parts.length; i++){
            values=parts[i].split("_");
            if(values[0]=="read" && values[1]==$_GET['read']){
                element.className="active";
            }
        }
    });

    if($$("form.validate").length>0){
        $$("form.validate")[0].onsubmit=function(){
    		dontsend=0;
    		$$("form.validate .required").each(function(element){
    			if(element.value==""){
    				element.fader=new Fx.Styles(element);
    				element.fader.start({
    					backgroundColor:"#FFCCCC"
    				});
    				dontsend=1;
    			} else {
    				element.fader=new Fx.Styles(element);
    				element.fader.start({
    					backgroundColor:"#FFFFFF"
    				});
    			}
    		});
    		if(dontsend==1){
    			return false;
    		} else {
    			return true;
    		}
    	}
    }
    if ($_GET['page']){
        show(1);
   }
   if (!$_GET['page']){

     showMiddle(1);
   }
});