google.load("jquery", "1");

var waysArray = null;
var newList;
var newPageIndex;
var currentPageIndex = pageIndex = 0;
var pageLinksNum = 1;
var pageIncrements = new Array(Array());
var listPath = "101ways.txt";

pageIncrements[0] = [1,10];
pageIncrements[1] = [11,20];
pageIncrements[2] = [21,30];
pageIncrements[3] = [31,40];
pageIncrements[4] = [41,50];
pageIncrements[5] = [51,60];
pageIncrements[6] = [61,70];
pageIncrements[7] = [71,80];
pageIncrements[8] = [81,90];
pageIncrements[9] = [91,101];

function loadWays() {
	$.get(listPath,{},function(data) {
   	waysArray = data.split("\n");
		changeWaysPage(1,10,0);
	});
}

function changeWaysPage(first,last,pageIndex) {
	newList = "";
	for (var i=(first-1);i<=(last-1);i++) {
		newList += "<tr><th>"+(i+1)+"</th><td>"+waysArray[i]+"</a></td></tr>";
		if (i<last-1) { newList += "<tr><td colspan=\"2\" class=\"Separator\"><img src=\"/dogsruleday/images/celebrate_list_separator.gif\" alt=\"\"></td></tr>"; }
	}
	$("#Celebrate_List_Items").html(newList);
	
	oldPageRangeIndex = oldPageRange = currentPageIndex;
	newPageRangeIndex = newPageRange = newPageIndex = pageIndex;
	
	if (pageLinksNum==2) {
		oldPageRangeIndex -= 5;
		newPageRangeIndex -= 5;
		oldPageRange += 5;
		//newPageRange += 5;

		if (newPageRangeIndex!=undefined) {
			$("#Page_Range_"+oldPageRangeIndex).attr("src","/dogsruleday/images/celebrate_list_"+(currentPageIndex)+"_off.gif");
			$("#Page_Range_"+newPageRangeIndex).attr("src","/dogsruleday/images/celebrate_list_"+(newPageRange)+"_on.gif");
		}
	} else {
		if (newPageRangeIndex!=undefined) {
			$("#Page_Range_"+oldPageRangeIndex).attr("src","/dogsruleday/images/celebrate_list_"+currentPageIndex+"_off.gif");
			$("#Page_Range_"+pageIndex).attr("src","/dogsruleday/images/celebrate_list_"+newPageRange+"_on.gif");
		}
	}
	
	if (newPageIndex<=0&&pageLinksNum==1) {
		$("#Celebrate_Prev_Arrow").attr("src","/dogsruleday/images/celebrate_list_prev_off.gif");
	} else {
		$("#Celebrate_Prev_Arrow").attr("src","/dogsruleday/images/celebrate_list_prev_on.gif");
	}
	
	if (newPageIndex>=pageIncrements.length-1) {
		$("#Celebrate_Next_Arrow").attr("src","/dogsruleday/images/celebrate_list_next_off.gif");
	} else {
		$("#Celebrate_Next_Arrow").attr("src","/dogsruleday/images/celebrate_list_next_on.gif");
	}
	
	for (var i=0;i<=4;i++) {
		if (pageLinksNum==2) {
			$("#Page_Link_"+i).attr("href","javascript:changeWaysPage("+(pageIncrements[i+5][0])+","+(pageIncrements[i+5][1])+","+(i+5)+");");
		} else {
			$("#Page_Link_"+i).attr("href","javascript:changeWaysPage("+pageIncrements[i][0]+","+pageIncrements[i][1]+","+i+");");
		}
	}
	
	omniTrack('DRD - 101 Ways to Celebrate - Page '+(pageIndex+1));
	
	currentPageIndex = pageIndex;
}

function navWaysPage(pageInc) {
	
	newPageIndex = currentPageIndex + pageInc;
	
	if (newPageIndex==5) { navWaysPageLinks(2); }
	if (newPageIndex==4) { navWaysPageLinks(1); }
	oldPageRange = currentPageIndex;
	newPageRange = newPageIndex;
	
	if (newPageIndex>=0&&newPageIndex<pageIncrements.length) {
		changeWaysPage(pageIncrements[newPageIndex][0],pageIncrements[newPageIndex][1],newPageIndex);
		currentPageIndex = newPageIndex;
	}
	
}

function navWaysPageLinks(newPageLinksNum) {
	var startAt = 0;
	if (newPageLinksNum==2) { startAt = 5; }
	for (var i=0;i<=4;i++) {
		var activeStatus = "off";
		if (newPageLinksNum==1&&i==4) { activeStatus = "on"; }
		if (newPageLinksNum==2&&i==0) { activeStatus = "on"; }
		$("#Page_Range_"+i).attr("src","/dogsruleday/images/celebrate_list_"+(startAt+i)+"_"+activeStatus+".gif");
	}
	
	pageLinksNum = newPageLinksNum;
}


var prevActivePhoto = 1;
var photoCaptions = new Array(8);
photoCaptions[1] = "I'm taking her hiking and swimming. She loves that stuff.";
//photoCaptions[2] = "We're just going to stay home, and practice looking adorable.";
photoCaptions[2] = "We love a good match of tug-of-war. I'll probably let him win.";
photoCaptions[3] = "We're gonna do what we all love to do&mdash;sleep the day away.";
photoCaptions[4] = "We'll play in the backyard until he gets tired. It's gonna be a long day.";
photoCaptions[5] = "Off to the beach. He loves the way the sun feels on his squishy little face.";
photoCaptions[6] = "We're going to the pet store so she can pick out a treat.";
photoCaptions[7] = "We're going for a walk. But it's getting chilly so we'll have to bundle up.";
photoCaptions[8] = "We're going wherever she wants. She's the boss.";


function initPhotos() {
	for (var i=1;i<=8;i++) {
		$("#Thumb_"+i+" img").bind("click",{photoID:i},openPhoto);

		window["Photo_Thumb_"+i] = new Image();
		window["Photo_Thumb_"+i].src = "/dogsruleday/images/photos/"+i+"_thm_on.jpg";
		window["Photo_Large_"+i] = new Image();
		window["Photo_Large_"+i].src = "/dogsruleday/images/photos/"+i+"_lrg.jpg";
	}
	$("#Thumb_1 img").unbind("click");
}

function openPhoto(event) {
	var photoID = event.data.photoID;
	
	$("#Large_Photo img").fadeOut("fast",function() {
		$("#Large_Photo img").attr("src","/dogsruleday/images/photos/"+photoID+"_lrg.jpg").fadeIn("fast");
	});
	
	$("#Thumb_"+photoID+" img").attr("src","/dogsruleday/images/photos/"+photoID+"_thm_on.jpg");
	$("#Thumb_"+photoID+" img").unbind("click");
	$("#Thumb_"+prevActivePhoto+" img").attr("src","/dogsruleday/images/photos/"+prevActivePhoto+"_thm_off.jpg");
	$("#Thumb_"+prevActivePhoto+" img").bind("click",{photoID:prevActivePhoto},openPhoto);
	$("#Thumb_"+photoID).toggleClass("Active");
	$("#Thumb_"+prevActivePhoto).toggleClass("Active");
	
	$("#Large_Photo p").html(photoCaptions[photoID]);
	
	prevActivePhoto = photoID;
	
}

function popupWindow(url,name,width,height,scroll) {
	if (scroll==null) { scroll = 'no'; }
	leftPosition = (screen.width) ? (screen.width-width) / 2 : 0;
	topPosition = (screen.height) ? (screen.height-height) / 2 : 0;
	settings = 'height='+height+',width='+width+',top='+topPosition+',left='+leftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(url,name,settings)
}

function sendAnalyticsEvent(accnt){
	accnt=accnt?accnt:s_account; void(s_gs(accnt))}
	function sendLinkEvent(accnt,lnkname,type){
	accnt=accnt?accnt:s_account;s_linkType=type?type:"o";s_lnk=true;
	s_linkName=lnkname?lnkname:s_linkName?s_linkName:"Flash Link Event";
	void(s_gs(accnt))
}

function omniTrack(pageName) {
	s_pageName = pageName;
	sendAnalyticsEvent('');
}