                                                                                                                                                                                                                                                                                                                                                                                
var thumbsPerPage = 5;
var totalThumbs = 0;
var thumbWidth = 90;
var currentThumb = 0;
var animSpeed = 300;


function initScrollPosition() {
	var distance = thumbWidth * (currentThumb) ;
	$('#work_thumbnails').css('left', "-" + distance + "px");
}			

function currentBottomProject() {
	return currentThumb + thumbsPerPage;
}

function checkNavArrows() {
	if (canScrollLeft()) {
		$('.thumbnail_container .leftControl a').css({ backgroundPosition: "top center", cursor: "pointer" });
	}
	else {	
		$('.thumbnail_container .leftControl a').css({ backgroundPosition: "top left", cursor: "default" });		
	}

	if (canScrollRight()) {
		$('.thumbnail_container .rightControl a').css({ backgroundPosition: "top center", cursor: "pointer" });		
	}
	else {
		$('.thumbnail_container .rightControl a').css({ backgroundPosition: "top right", cursor: "default" });		
	}
}	

function canScrollRight() {
	return (currentThumb > 0);
}			

function canScrollLeft() {
	return (currentBottomProject() < totalThumbs);
}			

function scrollRight() {
	var distance = thumbWidth * (currentThumb + 1);

	$("#work_thumbnails").animate({
		top: 0,
		left: -distance
	}, animSpeed );

	currentThumb += 1;					
	checkNavArrows();					
}			

function scrollLeft() {
	var distance = thumbWidth * (currentThumb - 1);

	$("#work_thumbnails").animate({ 
		top: 0,
		left: -distance
	}, animSpeed );

	currentThumb -= 1;					
	checkNavArrows();
}

function filterGalleryItems(){
	var oType = $("#galleryFilter option:selected").text();
	$(".galleryimages").each(function(){

		var myName = $(this).attr("name");
		
		if(oType == "View All"){
			$(this).fadeIn('slow');
		} else {
			if(myName != oType){
				$(this).hide();
					// .animate({opacity: 0}, 1000)
					// 				.animate({margin: '0px', height: '0px', overflow: 'hidden'}, 1000);
					
			} else {
				$(this).fadeIn('slow');
					// .animate({margin: '0px 0px 40px 0px', height: '73px', overflow: 'visible'}, 1000)
					// 				.animate({opacity: 1}, 1000);
			}
		}
	});
}

$(document).ready(function() {
    
    // $('#gallery_categories').hide();
	
	var totalulwidth = thumbWidth * totalThumbs;

	$("#work_thumbnails").css({
		width: totalulwidth
	});

	$('p.tags').each(function(){
	    var x = $(this).html(); 
	    lastComma = x.lastIndexOf(",");
	    x = x.substring(0, lastComma);
	    $(this).html(x + '</a>');
	});

	$('#work_thumbnails li:first a').addClass('selected');

	$('#work_thumbnails li a').click(function() {
		
		if($(this).hasClass('selected')) {} else {
			
			newImg = $('img', this).attr('rel');
			$('#work_thumbnails li a.selected').removeClass('selected');
			$(this).addClass('selected');
			
			$('#mainWindow img').fadeOut(300, function() {
				
				oImg = newImg;
				$('#loader').show();
				$('#mainWindow img').attr("src", oImg).css({ margin: "0 0 0 -9999px" }).show(function() {
					$('#mainWindow img').css({ margin: "0", display: "none" }).fadeIn(250);
					$('#loader').hide();
				});
				
			});
			
		}
		return false;
	});
	
	
	$('.galleryimages img').click(function() {
		
		if($(this).hasClass('selected')) {} else {
			
			newImg = $(this).attr('rel');
			newTitle = $(this).attr('alt');
			newDesc = $(this).attr('title');
			
			$('.galleryimages img.selected').removeClass('selected');
			$(this).addClass('selected');
			
			$('#galleryH3').fadeOut(300);
			$('#galleryDescription').fadeOut(300);
			$('#galleryImg img').fadeOut(300, function() {
				
				
				oImg = '/' + newImg;
				
				$('#loader').show();
				$('#galleryImg img').attr({ src: oImg }).css({ margin: "0 0 0 -9999px" }).show(function() {
					$('#loader').hide();
					$('#galleryImg img').css({ margin: "0", display: "none" }).fadeIn(250);
					$('#galleryH3').html(newTitle).fadeIn(250);
					$('#galleryDescription').html(newDesc).fadeIn(250);
					$('html, body').animate({scrollTop:0}, 'slow'); 
				});
				

				
			});
			
		}
		return false;
	});
	
	$("#navigation li").each(function(i){
		this.className = removeSpaces(this.className);
	});

	$("li.About a:first").attr("href","/Pages/Overview");
	$("li.Events a:first").attr("href","/Pages/Client+Profiles");
	$("li.Contact a:first").attr("href","/Pages/Request+Information");
	$("li.Newsletter a:first").attr("href","/Pages/Sign+Up");
	$("li.Press a:first").attr("href","/Pages/Press+Coverage");

	function removeSpaces(string) {
		return string.split(' ').join('');
	}

	try{$('#pressItems').innerfade({
		speed: 'slow', 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '15px' 
	});
	}catch(e){
        }
	/*$('.galleryImg').click(function() {
		$('#galleryImg').html('<img src=\'/'+$(this).attr('rel')+'\' />');
		$('#galleryH3').html($(this).attr('alt'));
		$('#galleryDescription').html($(this).attr('title'));
	});*/

// NEW GALLERY PAGE

	// $('#gallery_categories').hide();
	// $('#gallery_categories').fadeIn("3000");
	
    $('#gallery_categories .category img').each(function() {
        $(this).animate({ opacity:0.5 }, 500);
        $(this).hover(function() {
           $(this).stop().animate({ opacity: 1.0 }, 500);
        },
        function() {
           $(this).stop().animate({ opacity: 0.5 }, 500);
        });
    });
       


// HOMEPAGE HEIGHT CONTROL
	
	var recentNewsHeight = Math.max($('.featured_details').height(),$('#recent_news').height());
	
	$('#recent_news').height(recentNewsHeight);
	
});


// NAVIGATION IE6 FIX

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigation");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;


$(window).load(function () {
 $('#gallery_categories').fadeIn(2000);
});
    

    

    

    

    

    

    

    

    

    

    



    

    

    