var cur_index = 0;
var cur_photoAlbum = 0;
var leftArrowHtml = '<div id="arrowLeft" class="left hand" onclick="pagePhoto(0);"><<</div>';
var rightArrowHtml = '<div id="arrowRight" class="left hand" onclick="pagePhoto(1);">>></div>';	

$(document).ready(function(){
	$.fn.createDialog.defaults = {
		progress: true,
		center: true,
		opacity: 0.9,
		bg: '#E8E8E8'
    }
	$(".photoDiv").mousedown(function(){
		var id = $(this).attr("id");	
		$(this).createDialog({
			addr: 'album'+id+'.html'
		});
	});	
	$("img.navlink").mouseover(function(){
		var src = $(this).attr("src");
		src = src.substr(0, src.lastIndexOf('.gif')) + "_over.gif";
		$(this).attr("src",src);
	});	
	$("img.navlink").mouseout(function(){
		var src = $(this).attr("src");
		src = src.substr(0, src.lastIndexOf('_over.gif')) + ".gif";
		$(this).attr("src",src);		
	});		
});	

var arrPhotos = [
//	{id:"1",title:"2006 April",imgurl:"photo1.gif"},
//	{id:"2",title:"2006 August",imgurl:"photo2.gif"},
	{id:"3",title:"2006 July",imgurl:"photo3.gif"},
	{id:"4",title:"2006 June",imgurl:"photo4.gif"},
	{id:"5",title:"2006 May",imgurl:"photo5.gif"},	
	{id:"6",title:"2006 October Boo-Bash",imgurl:"photo7.gif"},
	{id:"7",title:"2006 September",imgurl:"photo6.gif"},
	{id:"8",title:"Adorable",imgurl:"photo8.gif"}
//	{id:"9",title:"Store Pictures",imgurl:"photo10.gif"}	
];

function drawPhotoAlbum() {
	for(i=0;i<arrPhotos.length;i++){
		var html = '<div id="'+arrPhotos[i].id+'" class="photoDiv">';
		html += '<div class="photoTitle">'+arrPhotos[i].title+'</div>';		
		html += '<div class="photoImg"><img src="'+arrPhotos[i].imgurl+'" /></div>';		
		html += '</div>';		
		document.write(html);		
	}
}

function scrollTo(id) {
	document.getElementById(id).scrollIntoView();
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
		aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

function loadPhoto(id){	
	$("#photoMain").html('<img src="'+photoArray[id].imgurl+'" />');		
	$("#photoText").html(photoArray[id].imgtext);	
}

function pagePhoto(iIndex){
	var html = '';
	if(iIndex == 0){
		cur_index = cur_index-1;	
	} else {
		cur_index = cur_index+1;	
	}
	if(cur_index != 0){
			html += leftArrowHtml;	
	}
	for(var i=cur_index;i<=photoArray.length;i++){
		if(i <= cur_index+6){
			html += '<div class="photoTN left hand" onclick="loadPhoto(\''+photoArray[i].id+'\')">';
			html += '<img src="'+photoArray[i].imgurl+'" width="100" height="100" />';			
			html += '</div>';
		}	
	}	
	if(photoArray.length > cur_index+7){
			html += rightArrowHtml;	
	}
	$("#photoContainer").html(html);	
}

function initPhotos(){
	var html = '';
	$("#photoMain").html('<img src="'+photoArray[0].imgurl+'" />');	
	$("#photoText").html(photoArray[0].imgtext);
	for(var i=0;i<photoArray.length;i++){
		if(i < 7){
			html += '<div class="photoTN left hand" onclick="loadPhoto(\''+photoArray[i].id+'\')">';
			html += '<img src="'+photoArray[i].imgurl+'" width="100" height="100" />';			
			html += '</div>';
		}	
	}	
	if(photoArray.length > 7){
			html += rightArrowHtml;	
	}
	$("#photoContainer").html(html);	
	cur_index = 0;
}