function loadTab(tab, tabcontainer, tabcontent)
{
	//alert('In load tab');
	
	tabcontainer.contents().find("a").removeClass("selected");
	tabcontent.empty().addClass("loadimage").html("Loading...");
	//preloader.show();
	
	$.ajax(
	{
		url: tab.attr("href"), 
		cache: true,
		success: function(message) 
		{			            	
			tabcontent.empty().append(message);
			//preloader.hide();             
			tabcontent.removeClass("loadimage");
		}
	 });
	 tab.addClass("selected");
}

function loadIntialContent(tabcontainer, tab, tabcontent, initialContent)
{
	//alert('In load Initial Content');
	tabcontainer.contents().find("a").removeClass("selected");

	tabcontent.empty().addClass("loadimage").html("Loading...");
	tabcontent.empty().append(initialContent.html());
	tabcontent.removeClass("loadimage");
	
	tab.addClass("selected");
	
}

$(document).ready(function()
{
	/* Read all DOM elements which have class name as tabcontainer, anchor tags in tabcontainere and assign click function if href is pointing 
	to url */
	$(".tabcontainer").each(function() {
			var tabcontainer = $(this);
			tabcontainer.siblings(".initialcontent").empty().append(tabcontainer.siblings(".tabcontent").html());
			tabcontainer.contents().find("a").filter(function(index) {
								return $(this).attr("href") != "#";
							}).click(function() {
								loadTab($(this), tabcontainer, tabcontainer.siblings(".tabcontent"));
								return false;
							});
			tabcontainer.contents().find("a").filter(function(index) {
				 return $(this).attr("href") == "#"; 
			}).click(function() {
				loadIntialContent(tabcontainer, $(this), tabcontainer.siblings(".tabcontent"), tabcontainer.siblings(".initialcontent"));
				return false;
			});
				
	});
});
