var entImg;
var odAr;
var curele = "home";
function init(){
	var a = window.location.href.split("#")[1];
	entImg = $('img[alt="Click Me"]'); 
	entImg.bind("mouseover", function(){entImg.animate({width: "300px"}, 50).animate({width:"255px", textAlign: "center"},500, "easeOutElastic")}); 
	entImg.bind("click", animate);
	if(a&&$('#'+a).length>0){curele=a;loadOd();entImg.css({display:"none"});}else{window.location.href="#"+curele;}
}
function animate(){
	entImg.animate({opacity: "0", width: "0px"}, 800, loadOd);
	entImg.unbind("mouseover");
	entImg.unbind("click");
}
function loadOd(){
	$('#scrollMe')[0].innerHTML = $('#'+curele)[0].innerHTML;
	$('#tabMe')[0].innerHTML = curele;
	$(".header").css({display : 'block'});
	$("img[alt='TextLogo']").css({display : 'block'});
	$("img[alt='TextLogo']").bind("mouseover", function(){$("img[alt='TextLogo']").animate({top: Math.floor(Math.random()*10)+150+"px", left: Math.floor(Math.random()*40)+100+"px"}, 1).animate({top:"150px",left:"100px"},150)}); 
	$('#scroller').animate({left: 1100}, 8000, "easeOutElastic").animate();
	$('.od').css({opacity:0,display:'block'});
	$('.opts div').css({opacity:0});
	$('#tabMe').css({opacity:0,display:'block'});
	$('#scrollMe').jScrollPane({showArrows:true});
	$('.od').animate({opacity:1},1000, function(){$('#tabMe').animate({opacity: 1,top: 240}, 1000, function(){
		$(this).css( {border:"1px solid", borderColor: "#888888", backgroundPosition: "-80px 50px"} );
		$('.opts div').animate({opacity:1},500, function(){
			$('.opts div').each(function (i) { 
				$(this).bind("mouseover",function(){
					$(this).stop().animate({marginTop: "-12px", paddingTop: '12px',backgroundPosition:"(60px 400px)"}, 280)
				});
				$(this).bind("mouseout", function(){
					$(this).stop().animate({marginTop: "0px", paddingTop: '0px', backgroundPosition:"(-80px 50px)"},100,function(){
						$(this).css({backgroundPosition: "-80px 50px"})
					})
				});
				$(this).bind("click", function(){
					loader(this.innerHTML);
				});
			});
		});
	}).animate();});
	$('#scrollMe').jScrollPane({showArrows:true});
}
function loader(e){
	var olde = curele;
	if(e!=curele){
		curele=e;
		window.location.href="#"+e;
		$('.opts div').unbind("click");
		$("#tabMe").animate({top:300,opacity:0},1000,function(){
			$('#scrollMe').animate({opacity:0},500);$("#content").animate({height: "20px"/*,opacity:0*/},1000, function(){
				$("#content").animate({height: "500px",opacity:1},1000,function(){
					$('#scrollMe').jScrollPaneRemove();
					$("#tabMe")[0].innerHTML=e;
					$('#'+olde)[0].innerHTML = $('#scrollMe')[0].innerHTML;
					$('#scrollMe')[0].innerHTML = $('#'+e)[0].innerHTML;
					$('#'+e)[0].innerHTML = "";
					$('#scrollMe').jScrollPane({showArrows:true});
					$('#scrollMe').wait().animate({opacity:1},500);
					$("#tabMe").animate({top:240,opacity:1},1000, function(){
						$('.opts div').bind("click", function(){
							loader(this.innerHTML);
						});
					});
				});
			});
		});
	}
}	
 $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
$(function(){
	$("a[rel='new']").each(function (i) {this.target = "_blank";});
	init();
});