var photoGallery = {
	currentPage:	0,
	totalPhotos: 	0,
	currentPhoto:   null,
	init:			function(totalPhotos){
		photoGallery.totalPhotos = totalPhotos;
		photoGallery.currentPhoto = $("photo0");
		for(var i = 0; i < totalPhotos; i++){
			$("photo"+i).observe("mouseover",function(event){
				photoGallery.currentPhoto.style.opacity = 0.75;
				photoGallery.currentPhoto.style.filter = "alpha(opacity=75)";
				this.style.opacity = 1;
				this.style.filter = "alpha(opacity=100)";
				photoGallery.currentPhoto = this;
				
			});
		}	
	},
	scrollLeft:		function (){
		//Make sure we're not on the first page
		if((photoGallery.currentPage - 4) >= 0){
			//Hide the current page
			for(var i = photoGallery.currentPage; i < (photoGallery.currentPage+4) && i < photoGallery.totalPhotos; i++){
				$('photo'+i).style.display = "none";
			}
			
			//Make the new page appear
			photoGallery.currentPage -= 4;
			for(var i = photoGallery.currentPage; (i < (photoGallery.currentPage+4)); i++){
				$('photo'+i).style.display = "block";
			}
		}
	},
	scrollRight:	function(){
		//Make sure we're not on the last page
		if((photoGallery.currentPage + 4) < (photoGallery.totalPhotos)){
			//Hide the current page
			for(var i = photoGallery.currentPage; i < (photoGallery.currentPage+4); i++){
				$('photo'+i).style.display = "none";
			}
						
			//Make the new page appear
			photoGallery.currentPage += 4;
			for(var i = photoGallery.currentPage; (i < (photoGallery.currentPage+4) && i < photoGallery.totalPhotos); i++){
				$('photo'+i).style.display = "block";
			}
		}
	},
	showPhotoPopup: function(id){
		var viewWidth = document.viewport.getWidth();
		var viewHeight = document.viewport.getHeight();
		var offsets   = document.viewport.getScrollOffsets();
		
		var eleDims = $("photoDetails"+id).getDimensions();
		var eleWidthOffset = eleDims["width"]/2;
		var eleHeightOffset = eleDims["height"]/2;
		if(viewHeight > eleDims["height"]){
			$("photoDetails"+id).style.top	= (viewHeight/2 - eleHeightOffset )  + "px";	
		}
		else {
			$("photoDetails"+id).style.top = offsets["top"] + "px";
		}
		
		if(viewWidth > eleDims["width"]){
			$("photoDetails"+id).style.left = (viewWidth/2  - eleWidthOffset)    + "px";
		}
		else {
			$("photoDetails"+id).style.left = offsets["left"] + "px";
		}
		
		new Draggable('photoDetails'+id, {
			scroll: window,
			zindex:999999,
			handle:"photoDetailsHandle"+id			
		});

		$("photoDetails"+id).style.display = "inline-block";
		
	},
	hidePhotoPopup: function(id){
		$("photoDetails"+id).style.display = "none";
	},
	prevPicture: function(id){
		this.hidePhotoPopup(id);
		this.showPhotoPopup(id-1);
	},
	nextPicture: function(id){
		this.hidePhotoPopup(id);
		this.showPhotoPopup(id+1);
	}
}



function switchToTab(tabId) {
	if($("test")) $("test").style.display = "none";
	if($("vend")) $("vend").style.display = "none";
	if($("prom")) $("prom").style.display = "none";
	if($("soci")) $("soci").style.display = "none";
	if($("vid")) $("vid").style.display = "none";
	if($("testTb")) $("testTb").style.backgroundColor = "#9E89C4";
	if($("vendTb")) $("vendTb").style.backgroundColor = "#9E89C4";
	if($("promTb")) $("promTb").style.backgroundColor = "#9E89C4";
	if($("sociTb")) $("sociTb").style.backgroundColor = "#9E89C4";
	if($("vidTb")) $("vidTb").style.backgroundColor = "#9E89C4";
	if($("testTb")) $("testTb").style.color = "white";
	if($("vendTb")) $("vendTb").style.color = "white";
	if($("promTb")) $("promTb").style.color = "white";
	if($("sociTb")) $("sociTb").style.color = "white";
	if($("vidTb")) $("vidTb").style.color = "white";
	
	if($(tabId)) $(tabId).style.display = "inline-block";
	if($(tabId + "Tb")) $(tabId + "Tb").style.backgroundColor = "#E0D9EC";
	if($(tabId + "Tb")) $(tabId + "Tb").style.color = "#5D4195";
}


var globalUserRating = 0;

function openRatingBox(starId, ratingFieldId){
	if(globalUserRating == 0){
		//$('rateNowContainer').show();
		Effect.BlindDown('rateNowContainer', { duration: 1 });
	}
	backFillStars(starId);
	globalUserRating = starId;
	var rateStars = $$('.rateStar');
	rateStars.each(function(star) { star.onmouseover = ""; } ); 
	if (ratingFieldId) {
		$(ratingFieldId).value = starId;
	}
	return false;
}

function backFillStars(starId){
	for(var i = 1; i <= 5; i++) {
		if(i <= starId)
			$("star"+i).style.backgroundImage = "url('/images/starfull.jpg')";
		else
			$("star"+i).style.backgroundImage = "url('/images/starempty.jpg')";
	}
}

Element.addMethods({
  redraw: function(element){
    element = $(element);
    var n = document.createTextNode(' ');
    element.appendChild(n);
    (function(){n.parentNode.removeChild(n)}).defer();
    return element;
  }
});
