function album_gray_out_thumb() {
	var mainImgSrc = $('#album_feat_img img').attr("src");
	var indexOfLastSlash = mainImgSrc.lastIndexOf("/");
	var mainImgFileName = mainImgSrc.substring((indexOfLastSlash+1));
	var smImgSrc = "/photo_gallery/thumb_size/" + mainImgFileName;
	$("#thumbnail_scroller ul li img[src='" +smImgSrc+ "']").addClass("currentImg");
	$('#thumbnail_scroller ul li img.currentImg').parent().css({'border-color':'#457E00'});
	
	var current = 0;
	$('#thumbnail_scroller ul li img').each(function(i){
		if($(this).hasClass('currentImg')) {
			current = i;
			return false;
		}
	});
	if($.cookie('view_all')==1)
		$('.view_all_thumbnails').click();
	else
		$('#thumbnail_scroller').trigger('goto',[current]);
};

function image_hover() {
	$('img.hover').hover (function() {		
		$(this).fadeTo('fast', 0.7);
	},
	function () {
		$(this).fadeTo('fast', 1);		
	});	
};

function adv_search_popup() {
	$('a.adv_search').cluetip({
		width:300,
		local:true, 
		hideLocal: true,
		positionBy: 'auto', 
		sticky: true, 
		arrows: false, 
		cursor: 'pointer', 
		activation: 'click',
		closePosition: 'title',
		cluetipClass: 'adv_search',
		showTitle: true,
		topOffset: -12,
		leftOffset: -105,
		cluezIndex: 5
	});
};

function read_more_popup() {
	$('a.read_more').show();
	$('a.read_more').click(function(){
		$('a.read_more_hidden').click();
	});
	$('a.read_more_hidden').cluetip({
		width:300,
		local:true, 
		hideLocal: true,
		positionBy: 'topLeft', 
		sticky: true, 
		arrows: false, 
		cursor: 'pointer', 
		activation: 'click',
		closePosition: 'top',
		cluetipClass: 'more_text',
		showTitle: false,
		topOffset: -10,
		leftOffset: -10,
		cluezIndex: 5
	});
};

function view_all_thumbnails() {
	var numPics = $('#thumbnail_scroller ul').children().length;/*determine the number of pictures in the scroller */
	var ulWidth = (92+5)*numPics /*calculate the length of the ul that holds the images, 84 is the width of the image, 5 is the combined margin for the left and right (2.5 px each)*/
	if (numPics > 7){
		$('.view_all_thumbnails').show().css({'margin-top':'-5px'});
	}
	$('.view_all_thumbnails').toggle(function(){
		$('#thumbnail_scroller').trigger('goto',[0]);									  
		$('.view_all_thumbnails a').text($('.view_all_thumbnails a').text() == 'VIEW ALL' ? 'VIEW LESS' : 'VIEW ALL');
		$('.prev').hide();
		$('.next').hide();
		$('#thumbnail_scroller').css({'width':'715px', 'height':'auto', 'left':'29px'});
		$('#thumbnail_scroller ul').css({'width':'715px'});
		$.cookie('view_all', 1);
		
	}, function(){
		$('.view_all_thumbnails a').text($('.view_all_thumbnails a').text() == 'VIEW ALL' ? 'VIEW LESS' : 'VIEW ALL');
		$('.prev').show();
		$('.next').show();
		$('#thumbnail_scroller').css({'overflow':'hidden', 'height':'70px', 'width':'675px', 'top':'5px', 'left':'5px'});
		$('#thumbnail_scroller ul').css({'width':ulWidth});
		$.cookie('view_all', 0);
	});
};

function album_thumnail_scroller() {
	var numPics = $('#thumbnail_scroller ul').children().length;/*determine the number of pictures in the scroller */
	var ulWidth = (92+5)*numPics /*calculate the length of the ul that holds the images, 84 is the width of the image, 5 is the combined margin for the left and right (2.5 px each)*/
	
	$('#thumbnail_scroller').css({'overflow':'hidden', 'height':'70px', 'width':'675px', 'top':'5px', 'left':'5px'});
	$('#thumbnail_scroller ul').css({'width':ulWidth});
	
	$('.prev').css({'display':'inline', 'cursor':'default'});
	$('.next').css({'display':'inline', 'cursor':'pointer'});
	if (numPics <= 7){
		$('.next').addClass('disabledNext');
		$('.prev').css({'margin-top':'25px'});
	}
	$('#thumbnail_scroller').serialScroll({
		items:'li',
		prev:'.prev',
		next:'.next',
		axis:'x',		
		step:7,
		easing:'linear',
		duration:1,
		constant:false,
		offset:-3,
		force:true,
		stop:true,
		lock:false,
		exclude:6,
		cycle:false, //don't pull back once you reach the end
		onBefore:function( e, elem, $pane, $items, pos ){
			$('.prev').removeClass('disabledPrev');
			$('.next').removeClass('disabledNext');
			//if at the beginning of the strip
			if( pos == 0 ){ 
				//gray out the prev arrow
				$('.prev').addClass('disabledPrev');
				//set the cursor to an arrow when over the prev arrow
				$('.prev').css('display', 'inline').css('cursor','default');
				/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
				$('.next').css('display', 'inline').css('cursor','pointer');
			}
			//if at the end of the strip
			else if( pos == $items.length-7){
				//gray out the next arrow
				$('.next').addClass('disabledNext');	
				//set the cursor to an arrow when over the next arrow
				$('.next').css('display', 'inline').css('cursor','default');
				/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
				$('.prev').css('display', 'inline').css('cursor','pointer');
			}
			//if anywhere in the middle
			else {
				/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
				$('.prev').css('display', 'inline').css('cursor','pointer');
				/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
				$('.next').css('display', 'inline').css('cursor','pointer');
			}
		}
	});
};

var linkUrl = '';
var bind_thickbox = function () {
    if (linkUrl != '') {
        var photo_id = parseInt(linkUrl.substr(16), 10);
        var url = $('#albumUrl').val() + '/photo-' + photo_id;
        window.location = url;
    }
};

var bind_fancybox = function () {
    $('.fancybox_gallery_link').fancybox({
        onClosed: bind_thickbox,
        type: 'iframe',
        titleShow: false,
        hideOnOverlayClick: false,
        autoDimensions: false,
        height: 650,
        width: 800
    });
};
