// ________________________________________________________
// Get query string
function __getQueryString(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if(results == null){
		return "";
	}else{
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
}

// ________________________________________________________
// Get
function __get(href, callback){
	var arr = {};
	if(href.indexOf("?") >= 0){
		href = href.replace(/&amp;/g, "&");
		var elm = href.substring(href.indexOf("?") + 1).split("&");
		for(var i = 0; i < elm.length; i++){
			var p = elm[i].split("=");
			arr[p[0]] = p[1];
		}
		href = href.substring(0, href.indexOf("?"));
	}
	
	$.get(href, arr, callback);
}

// ________________________________________________________
// Init
function __init(){
	// Player
	new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1"
	}, [
		{
			title: "Between The Lines",
			artist: "Southern Cross from 'From Tragedy'",
			free: false,
			mp3: "medias/00_Between.mp3"
		},
		{
			title: "Carousel",
			artist: "Southern Cross from 'From Tragedy'",
			free: false,
			mp3: "medias/01_Carousel.mp3"
		},
		{
			title: "Weak And Sober",
			artist: "Southern Cross from 'Down Below'",
			free: false,
			mp3: "medias/02_Weak_And_Sober.mp3"
		},
		{
			title: "Thirteen",
			artist: "Southern Cross from 'Down Below'",
			free: false,
			mp3: "medias/03_Thirteen.mp3"
		},
		{
			title: "Left For Dead",
			artist: "Southern Cross from 'Down Below'",
			free: false,
			mp3: "medias/04_Left_For_Dead.mp3"
		},
		{
			title: "The Third Gate",
			artist: "Southern Cross from 'Rise Above'",
			free: false,
			mp3: "medias/05_The_Third_Gate.mp3"
		},
		{
			title: "Rise Above",
			artist: "Southern Cross from 'Rise Above'",
			free: false,
			mp3: "medias/06_Rise_Above.mp3"
		}
	], {
		swfPath: "js",
		supplied: "mp3"
	});
	
	// External link
	$("a[rel*='external']").click(function(){
		this.target = "_blank";
	});
	
	// Lightbox
	if($("a[rel*='lightbox']").length > 0){
		$("a[rel*='lightbox']").colorbox();
	}
	
	// Facebook button
	var href = escape("http://facebook.com/southerncrossmetal");
	var locale = $.lang == "fr" ? "fr_FR" : "en_US";
	var layout = "button_count"; // standard
	$(".fblike").html('<iframe src="http://facebook.com/plugins/like.php?locale=' + locale + '&amp;href=' + href + '&amp;layout=' + layout + '&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;width=90&amp;height=25&amp;font=arial" scrolling="no" frameborder="0"  allowTransparency="true" style="border:none;overflow:hidden;width:90px;height:25px;"></iframe>');
	
	// Share page
	$(".fbshare a").click(function(e){
		window.open($(this).attr("href"), "fbshare", "width=500,height=400");
		return false;
	});
}

$(document).ready(function(){
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	$.browser.ios = /iPhone/i.test(window.navigator.userAgent) || /iPod/i.test(window.navigator.userAgent) || /iPad/i.test(window.navigator.userAgent);
	$.lang = window.location.href.indexOf("/en/") > 0 ? "en" : "fr";
	
	__init();
});
