$(document).ready(function(){
	
	
/*------------------------------------------------------------------------------------*/
// Artist Content - the video area, tour dates, photos, trivia, and more-artist
// modules are updated when a user selects a video channel. The initial artist can be
// set by passing a value in the querystring. Ex: ?artist=3
/*------------------------------------------------------------------------------------*/

	// set initial vars
	var lastChannel;
	var firstChannel;
	var requestedArtist = $.query.get("artist")+"";
	
	// on load show all channels in "off" state
	$("#rri-playlist-off-1").show();
	$("#rri-playlist-off-2").show();
	$("#rri-playlist-off-3").show();
	$("#rri-playlist-off-4").show();
		
		
	// load initial artist states
	switch(requestedArtist) {
		
		case "1": // whiteney
		initialArtist("1");
		break;
	
		case "2": // little big town
		initialArtist("2");
		break;
	
		case "3": // phil
		initialArtist("3");
		break;
	
		case "4": // kingbilly
		initialArtist("4");
		break;
		
		default: // if nothing passed in querystring show whitney
		initialArtist("1");
		
	}
	
	function initialArtist(artistNum) {
		
		// hide initial playlist "off" state
		$("#rri-playlist-off-"+artistNum).hide();
		
		// hide initial playlist "on" state
		$("#rri-playlist-on-"+artistNum).show();
		
		// show initial on the road
		$("#rri-ontheroad-"+artistNum).show();
		
		// show initial photo gallery
		$("#rri-photos-"+artistNum).show();
		
		// show initial "trivia" (only if LBT(2) or phil(3))
		if (artistNum == "2" || artistNum == "3") {
			$("#rri-trivia-"+artistNum).show();
		}
		
		// show first "more" content - on load
		$("#rri-more-"+artistNum).show();
		
		// set initial video channel id for sniPUPObj
		firstChannel = $("#rri-playlist-off-"+artistNum+" a").attr("id");
	
		// set last channel to default artist number
		lastChannel = artistNum;
	
	}
	
	// show clicked channel's reated content hide last channel content
	function showCurrentChannel(newChannel) {
		
		$("#rri-playlist-on-"+lastChannel).hide();// hide last channel "on" state
		$("#rri-playlist-off-"+newChannel).hide();// hide new channel "off" state
		$("#rri-playlist-off-"+lastChannel).show();// show last channel "of" state
		$("#rri-playlist-on-"+newChannel).show(); // show new channel "on" state
		$("#rri-ontheroad-"+lastChannel).hide();// hide last on the road content
		$("#rri-ontheroad-"+newChannel).show();// show new on the road content
		$("#rri-photos-"+lastChannel).hide();// hide last photos content
		$("#rri-photos-"+newChannel).show();// show new photos content
		
		// because not all trivia div's should appear, only try to show/hide those that exist.
		if($("#rri-trivia-"+lastChannel).length > 0) $("#rri-trivia-"+lastChannel).hide();// hide last trivia content
		if($("#rri-trivia-"+newChannel).length > 0) {
			$("#rri-trivia-"+newChannel).show();// show new trivia content
			$("#rri-card").css("padding-top", "18px");// adjust padding
		}
		else {;
			$("#rri-card").css("padding-top", "0px");// revert padding
		}
		
		$("#rri-more-"+lastChannel).hide();// hide last more content
		$("#rri-more-"+newChannel).show();// show new more content
		
		lastChannel = newChannel; // update last channel variable
		
	}
	
	// when a channel is clicked 
	$("#rri-playlist a").bind("click", function() {
		
		switch($(this).parent().attr("id")) {
		
			case "rri-playlist-off-1": // whiteney
			showCurrentChannel("1");
			break;
		
			case "rri-playlist-off-2": // little big town
			showCurrentChannel("2");
			break;
		
			case "rri-playlist-off-3": // phil
			showCurrentChannel("3");
			break;
		
			case "rri-playlist-off-4": // kingbilly
			showCurrentChannel("4");
			break;
			
		}
		
		switchChannel($(this).attr("id"));
    });
	
	// load new channel
	function switchChannel(id) {
	  sniPUPObj.channelID = id;
	  sniPUPObj.write();
	  return false;
	};

	// default video params
	var sniPUPObj = new sniPUP("rri_video_player");
	sniPUPObj.channelID = firstChannel; 
	sniPUPObj.lcDivName = "lcBannerDiv";
	sniPUPObj.autoPlay = "true";
    //sniPUPObj.showList = "false";
	sniPUPObj.hasSearch = "false";
	sniPUPObj.siteID = "GAC";
	//sniPUPObj.configXML = "http://images.gactv.com/_xml/pupstyles.xml";
	sniPUPObj.write();

	
/*------------------------------------------------------------------------------------*/
// Share Popup
/*------------------------------------------------------------------------------------*/

	
	$("#rri-share").click(function () {	
									
		var sharePath;
		
		switch(lastChannel) {
		
			case "1": // whitney
			sharePath = "http://images.gactv.com/util/sendFriend/sendFriend.html?msg=rr09whitney";
			break;
		
			case "2": // little big town
			sharePath = "http://images.gactv.com/util/sendFriend/sendFriend.html?msg=rr08littlebigtown";
			break;
		
			case "3": // phil
			sharePath = "http://images.gactv.com/util/sendFriend/sendFriend.html?msg=rr08phil";
			break;
		
			case "4": // kingbilly
			sharePath = "http://images.gactv.com/util/sendFriend/sendFriend.html?msg=rr08kingbilly";
			break;
			
		}
		
		window.open (sharePath,"newWindow","location=1,status=1,scrollbars=no,resizable=no,width=519,height=600");
    });
	
	
	
	
/*------------------------------------------------------------------------------------*/
// Tips Pagination
/*------------------------------------------------------------------------------------*/
	
	var pageTotal = $("#rri-tips-cnt").find(".rri-tips-page").length;
	var lastPage = 1;
	var nextPage;
	var previousPage;
	var paginationContent = "";
	
	
	// create the pagination per the amount of tip div's
	var t=1;
	for (t=1;t<=pageTotal;t++) {
		paginationContent = paginationContent + '<span id="rri-tips-p-'+t+'">'+t+'</span>';
	}
	
	// after loop update the html of the pagination container
	$("#rri-tips-pagination").html(paginationContent);
	
	// set initial page
	updatePagination(1,1);

	function updatePagination(oldP, newP) {
		
		// reset last page number's style
		$("#rri-tips-pagination #rri-tips-p-"+oldP).css("color", "#27103d");
		$("#rri-tips-pagination #rri-tips-p-"+oldP).css("background-color", "");
		$("#rri-tips-pagination #rri-tips-p-"+oldP).css("padding","1px 3px");
		
		// update new page number's style
		$("#rri-tips-pagination #rri-tips-p-"+newP).css("color","#fff");
		$("#rri-tips-pagination #rri-tips-p-"+newP).css("background-color", "#27103d");
		$("#rri-tips-pagination #rri-tips-p-"+newP).css("padding", "1px 4px");
		
	}
	
	// when a channel is clicked 
	$("#rri-tips-pagination span").bind("click", function() {
		
		newPage = $(this).html();
		$("#rri-tips-"+lastPage).hide();
		$("#rri-tips-"+newPage).show();
		
		updatePagination(lastPage, newPage);
		lastPage = parseInt(newPage);
		
		//switchChannel($(this).attr("id"));
    });
	
	
	
	// go to next page (keep circular)
	$("#rri-tips-next").click(function () {
		
		nextPage = (lastPage+1)+"";
		
		if (lastPage == pageTotal) {
			nextPage = "1"; 
		}
		else {
			nextPage = (lastPage+1)+"";
		}
		
		switch(lastPage) {
			case 1:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-"+nextPage).show();
			updatePagination(lastPage,nextPage);
			lastPage = parseInt(nextPage);
			break;
			
			case pageTotal:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-1").show();
			updatePagination(lastPage,nextPage);
			lastPage = parseInt(nextPage);
			break;
			
			default:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-"+nextPage).show();
			updatePagination(lastPage,nextPage);
			lastPage = parseInt(nextPage);
			break;
		}
    });
	
	// go to previous page (keep circular)
	$("#rri-tips-previous").click(function () {
		
		
		if (lastPage == 1) {
			previousPage = pageTotal+""; 
		}
		else {
			previousPage = (lastPage-1)+"";
		}
		
		switch(lastPage) {
			case 1:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-"+previousPage).show();
			updatePagination(lastPage,previousPage);
			lastPage = parseInt(previousPage);
			break;
			
			case pageTotal:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-"+previousPage).show();
			updatePagination(lastPage,previousPage);
			lastPage = parseInt(previousPage);
			break;
			
			default:
			$("#rri-tips-"+lastPage).hide();
			$("#rri-tips-"+previousPage).show();
			updatePagination(lastPage,previousPage);
			lastPage = parseInt(previousPage);
			break;
		}

    });
	


/*------------------------------------------------------------------------------------*/
// Make rail and content heights equal
/*------------------------------------------------------------------------------------*/
	
	var contentHeight = $("#rri-main").height();
	
	$("#rri-rail").css("height", contentHeight);

	
});