var CP={
	init:function(){
		$("body").addClass("js");
		CP.Features.init();
		CP.Util.equalize("#meta>div");
	},
	Features:{
		init:function(){
			slides.init($(".panels"));
			
		}
	},
	Util:{
		equalize:function(selector){
			var maxHeight=1;
			$(selector).each(function(){
				if (this.offsetHeight>maxHeight) maxHeight=this.offsetHeight;
			});
			$(selector).css("height",maxHeight+"px");
		}
	}
}

var slides={
	container:null,
	panels:Array(),
	init:function(container){
		slides.container=$(container);
		$('.panel',slides.container).each(
			function(i){
				var newPanel={};
				newPanel.element=this;
				newPanel.id=this.id;
				newPanel.index=i;
				newPanel.title=$('h2',this)[0];
				newPanel.tab=slides.createTab(newPanel);
				slides.panels[i]=newPanel;
				
			}
		)
		slides.createslidesBar();
		slides.showPanel(slides.panels[0]);
	},
	createTab:function(panel){
		var tab=document.createElement("li");
		var tabLink=document.createElement("a");
		tabLink.innerHTML=panel.title.innerHTML;
		tabLink.href="#"+panel.id;
		$(tabLink).click(function() {slides.showPanel(panel); return false;})
		tab.appendChild(tabLink);
		return tab;
		
	},
	createslidesBar:function(){
		var slidesParent=$(".welcome_box_content")[0];
		var ul=document.createElement("ul");
		$(slides.panels).each(function(){ ul.appendChild(this.tab); });
		var tabBar=document.createElement("div");
		tabBar.className="slides";
		tabBar.appendChild(ul);
		slidesParent.appendChild(tabBar);

		next=document.createElement("a");
		next.className="next";
		next.innerHTML="&raquo;";
		next.href="#";
		$(next).click(function() {slides.showNextPanel(); return false;})

		previous=document.createElement("a");
		previous.className="previous";
		previous.innerHTML="&laquo;";
		previous.href="#";
		$(previous).click(function() {slides.showPreviousPanel(); return false;})

		

		tabBar.appendChild(next);
		tabBar.appendChild(previous);

	},
	showNextPanel:function(){
		if (slides.activePanelIndex<(slides.panels.length-1)){
			nextIndex=slides.activePanelIndex+1;
		}else{
			nextIndex=0;
		}
		slides.showPanel(slides.panels[nextIndex]);

		update_lower_section();

	},
	showPreviousPanel:function(){
		if (slides.activePanelIndex>(0)){
			nextIndex=slides.activePanelIndex-1;
		}else{
			nextIndex=slides.panels.length-1;
		}
		slides.showPanel(slides.panels[nextIndex]);
		
		update_lower_section();
	},
	showPanel:function(panel){
		var l = ($(".welcome_box_content")[0].clientWidth)*panel.index;
		slides.container.animate({left:"-"+l+"px"},"slow","easeboth");
		slides.activeTab(panel.tab);
		slides.activePanelIndex=panel.index;
		update_lower_section();
	},
	activeTab:function(tab){
		$("#features li.active").each(function(){$(this).removeClass("active")});
		tab.className="active";
		$(tab).DropInUp(250);
	}

}


$(document).ready(function(){
	CP.init()}
	);



function update_lower_section(){
		if (slides.activePanelIndex == 0){
		loadpage("home");
		}	

		if (slides.activePanelIndex == 1){
		loadpage("order_a_cab");
		}
		
		if (slides.activePanelIndex == 2){
		loadpage("about_us");
		}
		
		if (slides.activePanelIndex == 3){
		loadpage("contact_us");	
		}
		
}


function loadpage(name){
$("#ajax_replace").load(name + ".php");
}

function scroll_to(id){
slides.showPanel(slides.panels[id]);
}




function description_show(name){

description_clear();
document.getElementById("description_" + "home").style.display = "none";
document.getElementById("description_" + name).style.display = "block";
}



function description_clear(){
document.getElementById("description_" + "one").style.display = "none";
document.getElementById("description_" + "two").style.display = "none";
document.getElementById("description_" + "three").style.display = "none";
document.getElementById("description_" + "four").style.display = "none";	
document.getElementById("description_" + "home").style.display = "block";
}



function signup(){
	close_all();
	document.getElementById('hidden_signupbox').style.display ='block';	
}


function login(){
	close_all();
	document.getElementById('hidden_loginbox').style.display ='block';	
}




function close_all(){
	document.getElementById('hidden_signupbox').style.display ='none';	
	document.getElementById('hidden_loginbox').style.display ='none';	
}


