$(document).ready(function() {
	Cufon.replace("#nav li a");
	Cufon.replace(".selected",{color:"#00487f",textShadow:'1px 1px #c4c4c4'});
	strpos = function (haystack, needle, offset) {
		var i = (haystack+'').indexOf(needle, (offset || 0));
		return i === -1 ? false : i;
	}
	$.fn.changetab = function(int,title,seo) {
		var height = 0;
		var background = '';
		switch(int) {
			case 0:
				height = 333;
			break;
			case 1:
				height = 330;
			break;
			case 2:
				height = 415;
			break;
			case 3:
				height = 1004;
			break;
			case 4:
				height = 540;
			break;
			case 5:
				height = 460;
			break;
			case 6:
				height = 1500;
			break;
			case 7:
				height = 3008;
			break;
		}
		window.location.href = "#/"+seo;
		$(this).animate({"height":height+"px","marginLeft":(int*999*-1)+"px"},750,"easeOutExpo",function() {
			document.title = title+" - Bravocrazy.com";
		});
	}
	
	if(strpos(window.location.href,"#/")) {
		var obj = $('a[seo="'+window.location.href.substr(strpos(window.location.href,"#/")+2)+'"]');
		$("#belt").stop(true,true).changetab(obj.parent().index(),obj.attr("section"),obj.attr("seo"));
		$(".selected").removeClass("selected");
		obj.addClass("selected");
		Cufon.replace("#nav li a",{color:"#868686",textShadow:'none'});
		Cufon.replace(".selected",{color:"#00487f",textShadow:'1px 1px #c4c4c4'});
	}
	
	$("#share").hover(function() {
		$(this).stop(true).animate({"marginLeft":"-63px"},500);
	},function() {
		$(this).stop(true).animate({"marginLeft":"-40px"},500);
	});
	
	$("#nav li a").live("click",function() {
		$("#belt").stop(true,true).changetab($(this).parent().index(),$(this).attr("section"),$(this).attr("seo"));
		$(".selected").removeClass("selected");
		$(this).addClass("selected");
		Cufon.replace("#nav li a",{color:"#868686",textShadow:'none'});
		Cufon.replace(".selected",{color:"#00487f",textShadow:'1px 1px #c4c4c4'});
	});
	
	$('a[rel="external"]').live("click",function(e) {
		/*
		var patt=/itunes/i;
		var result=patt.exec($(this).attr("href"));
		if(result == null) {
			$(".external .popup div").empty().append($(this).attr("href"));
		} else {
			$(".external .popup div").empty().append("http://itunes.apple.com/");
		}
		*/
		$(".external .popup div").empty().append($(this).attr("href"));
		$(".external .popup #close").attr("href",$(this).attr("href"));
		e.preventDefault();
		//alert(($(".popup").width()*1));
		$(".external").show();
		$(".popup").css("marginLeft","-"+($(".popup").width()*1/2)+"px");
		$(".external").hide();
		//$(".external .popup ").css("marginLeft","10000px");
		$(".external").fadeIn(500,function() {
			
		});
	});
	
	$("#close").live("click",function(e) {
		e.preventDefault();
		window.open($(this).attr("href"));
	});
	
	$("#close,.closeno").live("click",function() {
		$(".external").fadeOut(500);
	});
});
