// global window.load function
$(window).load(function() {
	removeLoadingClass("pageLoading");
	$("a[href^='http://'], a[href^='www.']").oinw();
});

// global document ready function
$(function() {
	$(".labeler").labeler();
	createSlides();
	createTabs();
	if($("a.lightbox").length>=1) {
		createLightBox("a.lightbox");
	}
	createPuzzle(".puzzle");
});

// slides
function createSlides() {
	$(".slides").cycle({slideExpr:"img"});
	$(".foot_bar ul.right").cycle();
}

// tabs
function createTabs() {
	$(".tabs").tabs();
};

// latest updates panel
$(function() {
	if($(".homepage_latest_updates").length>=1) {
		latestUpdatesPanel();
	}
	
	function latestUpdatesPanel() {
		$(".homepage_latest_updates ul li:first").addClass("active");
		$(".homepage_latest_updates ul li:last").addClass("last-child");
		// mouse over
		$(".homepage_latest_updates ul li").mouseenter(function() {
			if($(this).hasClass("active")) {
				// do nothing
			}
			else {
				$(".homepage_latest_updates ul li:not(this)").removeClass("active");
				$(this).addClass("active");
			}
		});
	}
});

// lightbox
function createLightBox(lightBoxClass) {
	$(lightBoxClass).lightBox({
		txtImage: 'image'
	});
}

// lyrics accordion
$(function() {
	$("#lyrics_accordion").accordion({
		collapsible: true,
		active: false,
		autoHeight: false,
		clearStyle: true
	});
});

function createPuzzle(puzzleClass) {
	$(puzzleClass).sortable();
	$(puzzleClass).disableSelection();
}

// remove loading class from html element
function removeLoadingClass(loadingClassName) {
	$("html").removeClass(loadingClassName);
}


$(function() {
	$("#footer_tweet").tweet({
		join_text: "auto",
		username: "alicerockmusic",
		avatar_size: 0,
		count: 1,
		auto_join_text_default: "we said:", 
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets..."
	});
	if($("body.ar_page_home").length==1) {
		$("#twitter_homepage").tweet({
			join_text: "auto",
			username: "alicerockmusic",
			avatar_size: 0,
			count: 1,
			auto_join_text_default: "we said:", 
			auto_join_text_ed: "we",
			auto_join_text_ing: "we were",
			auto_join_text_reply: "we replied",
			auto_join_text_url: "we were checking out",
			loading_text: "loading tweets..."
		});
	}
	if($("body.ar_page_blogs").length==1) {
		$("#blog_display").tweet({
			join_text: "auto",
			username: "alicerockmusic",
			avatar_size: 0,
			count: 10,
			auto_join_text_default: "we said:", 
			auto_join_text_ed: "we",
			auto_join_text_ing: "we were",
			auto_join_text_reply: "we replied",
			auto_join_text_url: "we were checking out",
			loading_text: "loading tweets..."
		});
	}
});