$(document).ready(function(){

appendSection('home');
appendSection('music');
appendSection('live');
appendSection('photos');
appendSection('shop');
appendSection('press');
appendSection('band');
appendSection('network');
appendSection('contact');
appendSection('tjiu');
appendSection('entry');


	if (location.search == "?shop") {
		viewSection("shop");
	} 


else if (location.search == "?thejigisup") {
	viewSection("tjiu");
}

else if (location.search == "?home") {
	viewSection("entry");
}

else if (location.search == "?music") {
	viewSection("music");
}

	 else {
		viewSection("entry");
	}
	


	$("#email").val("");
	$("#name").val("");


$(".home_link").attr({
		onClick: "viewSection('Home')",
		style: "cursor:pointer"
});

$(".entry_link").attr({
		onClick: "viewSection('Entry')",
		style: "cursor:pointer"
});

$(".music_link").attr({
		onClick: "viewSection('Music')",
		style: "cursor:pointer"
});

$(".live_link").attr({
		onClick: "viewSection('Live')",
		style: "cursor:pointer"
});


$(".photos_link").attr({
		onClick: "viewSection('Photos')",
		style: "cursor:pointer"
});

$(".shop_link").attr({
		onClick: "viewSection('Shop')",
		style: "cursor:pointer"
});

$(".press_link").attr({
		onClick: "viewSection('Press')",
		style: "cursor:pointer"
});

$(".band_link").attr({
		onClick: "viewSection('Band')",
		style: "cursor:pointer"
});

$(".network_link").attr({
		onClick: "viewSection('Network')",
		style: "cursor:pointer"
});

$(".contact_link").attr({
		onClick: "viewSection('Contact')",
		style: "cursor:pointer"
});


$(".tjiu_link").attr({
		onClick: "viewSection('tjiu')",
		style: "cursor:pointer"
});

$(".itsokwereok_link").attr({
		onClick: "viewSection('entry')",
		style: "cursor:pointer"
});

	$(".swoom_link").attr({
		onClick: "MM_openBrWindow('http://www.swoomrecords.com','','');",		
		style: "cursor:pointer"
    });

	$(".37_link").attr({
		onClick: "MM_openBrWindow('http://www.37ft.com','','');",		
		style: "cursor:pointer"
    });

	$(".facebook_link").attr({
		onClick: "MM_openBrWindow('http://www.facebook.com/vary.lumar','','');",
		style: "cursor:pointer"
    });

	$(".fblike_link").attr({
		onClick: "MM_openBrWindow('http://www.facebook.com/pages/Vary-Lumar/29474991801','','');",
		style: "cursor:pointer"
    });

	$(".vimeo_link").attr({
		onClick: "MM_openBrWindow('http://www.vimeo.com/user4573347/videos','','');",
		style: "cursor:pointer"
    });

	$(".youtube_link").attr({
		onClick: "MM_openBrWindow('http://www.youtube.com/varylumar','','');",
		style: "cursor:pointer"
    });
	
	$(".itunes_link").attr({
		onClick: "MM_openBrWindow('http://itunes.apple.com/us/artist/vary-lumar/id274172035','','');",
		style: "cursor:pointer"
    });

	$(".twitter_link").attr({
		onClick: "MM_openBrWindow('http://www.twitter.com/varylumar','','');",
		style: "cursor:pointer"
    });

	$(".amazon_link").attr({
		onClick: "MM_openBrWindow('http://www.amazon.com/s/ref=nb_ss?url=search-alias%3Ddigital-music&field-keywords=vary+lumar&x=0&y=0','','');",
		style: "cursor:pointer"
    });
	
	$(".napster_link").attr({
		onClick: "MM_openBrWindow('http://home.napster.com/ns/music/artist_search.html?artist_id=12540701','','');",
		style: "cursor:pointer"
    });
	
	$(".rhapsody_link").attr({
		onClick: "MM_openBrWindow('http://www.rhapsody.com/vary-lumar/plasticolor-coma-ep','','');",
		style: "cursor:pointer"
    });

	$(".ilike_link").attr({
		onClick: "MM_openBrWindow('http://www.ilike.com/artist/Vary+Lumar','','');",
		style: "cursor:pointer"
    });

	$(".reverbnation_link").attr({
		onClick: "MM_openBrWindow('http://www.reverbnation.com/varylumar','','');",
		style: "cursor:pointer"
    });

	$(".lastfm_link").attr({
		onClick: "MM_openBrWindow('http://www.last.fm/music/Vary%20Lumar','','');",
		style: "cursor:pointer"
    });




});


function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}



function appendSection(mixedCaseName) {

	name = mixedCaseName.toLowerCase();

//	appendSectionButton(name);

	appendSectionIframe(name);
}

function appendSectionButton(name) {

	
	var buttonGraphicName=document.createElement("img");
	buttonGraphicName.src="images/" + name + ".png";
	buttonGraphicName.width = "80";
	buttonGraphicName.height = "60";
	$(buttonGraphicName).attr({
		onClick: "viewSection('" + name + "')",
		onmouseover: "src='images/" + name + "swap.png'",
		onmouseout: "src='images/" + name + ".png'",
		id: name+"_button",
		style: "cursor:pointer"
	});
	
	$("#section_list").append(buttonGraphicName);
	
}




function appendSectionIframe(name) {

	var newIFrame = document.createElement("iframe");
	
	$(newIFrame).attr({
		id: name + "_section",
		name: name + "_section",
		src: name + "_section.html",
		display: "none",
allowtransparency: "true",
frameborder: "0"
	}); 
    $(newIFrame).hide();


	$("#section_contents").append(newIFrame);

}

function viewSection(name) {
	
	name = name.toLowerCase();


    $(".visible_section").fadeOut(0500, function() {
		$("#" + name + "_section").attr("display", "none");
	});
	$(".visible_section").attr("class", "");

    $("#" + name + "_section").attr("class","visible_section");
	$(".visible_section").fadeIn(1000);
	
	//pageTracker._trackPageview('/sections/' + name);
}

$(function() {
	$("#submit_btn").click(function() {
		var email = $("input#email").val();
		var name = $("input#name").val();
		
		pageTracker._trackPageview('/mailinglist/subscribe');
		pageTracker._trackPageview('/mailinglist/subscribe/'+email);
		
		var payload = "name=" + name + "&email=" + email;
		$("#welcome,#problem_registering").hide();
		if (email != "") {
			$.ajax({
				type: "POST",
				url: "mailer.php",
				data: payload,
				success: function(data, textStatus) {
					//alert("success: " + data)
					if (data.indexOf("invalid") != -1) {
						$("#problem_registering").text("Problem registering:  " + data);
						$("#problem_registering").fadeIn(1000);
						pageTracker._trackPageview('/mailinglist/fail/' + data);
					} else {
						$("#welcome").fadeIn(1000);
						$("#contact_form").fadeOut(1000);
						pageTracker._trackPageview('/mailinglist/success');
					}
					//alert("data: " + data + ", status: " + textStatus);
				},
				error: function(request, textStatus, errorText) {
					$("#problem_registering").text("Problem registering:  " + errorText);
					$("#problem_registering").fadeIn(1000);
					pageTracker._trackPageview('/mailinglist/fail/' + errorText);
					//alert("error status: " + textStatus + ", text: " + errorText);
				},
			});
		}
		return false;
	});
});




