(function($) { 

	$.generic = {

		navbg: null,

		navopacity: null,

		init: function(navbg,navopacity){

			$.generic.navbg = navbg;
			$.generic.navopacity = navopacity;

			this.navigation();
			this.binds();
		},

		navigation: function(){
			var filter = 'alpha(opacity=' + $.generic.navopacity*100 + ')'
			$("#navigation").transBGdraw({'background': $.generic.navbg, 'opacity': $.generic.navopacity, '-moz-opacity': $.generic.navopacity,'filter': filter });
		},

		binds: function(){
			$(".scrollleft").live('click',function(e){
				e.preventDefault();
				$(window).scrollTo({top:0,left:0},800);
			});
		},

		collapsablenav: function() {
			var pathArray = window.location.pathname;
			var url = "";
			for (var i = 0; i < pathArray.length; i++) {
				url += pathArray[i];
			}

			$(".subnav").each(function(){



				$(".subnav").parent().find('a:first').addClass('arrowdown');	
				var urlmatch = 0;
		

				if(url != "/") {
					$(this).find('li').each(function(){

						var currLink = $(this).find('a');
						
						if(currLink.attr('href')) {

							if(currLink.attr('href').indexOf(url) > -1) {

								urlmatch = 1;

							}

						}

					});
				}
					

				if(urlmatch == 0) {

					$(this).hide();

				}

					

				$(this).parent().find('a:first').bind('click',function(e) {

					e.preventDefault();

					$(this).parent().find('.subnav').slideToggle();

				});

			});

			

			var Duration = 250; //time in milliseconds

			var Duration2 = 150; //time in milliseconds

			jQuery('a.arrowright').hover(function() {

				jQuery(this).stop().animate({ paddingLeft: '20px' }, Duration);

			}, function() {

				jQuery(this).stop().animate({ paddingLeft: '0px' }, Duration);

			});	

			

			jQuery('a.arrowrightsub').hover(function() {

				jQuery(this).stop().animate({ paddingLeft: '20px' }, Duration);

			}, function() {

				jQuery(this).stop().animate({ paddingLeft: '0px' }, Duration);

			});	

			

		}

	},

	$.rectangle_layout = {
		init: function(){
			Shadowbox.init({
			   troubleElements: ["select"]
			});
		}
	},
	$.smallsquare_layout = {
		init: function(){
			Shadowbox.init({
			   displayCounter: false,
			   troubleElements: ["select"]
			});
		}
	},
	$.vertlargeimg_layout = {
		init: function(){
			
		}
	}
	$.largeimg_layout = {

		init: function(){

			var totalwidths = 0;
			$(".largeimg_layout img").each(function(){
				totalwidths += $(this).width() + 20;
			});

			$(".largeimg_layout,.largeimg_layout ul").css('width',totalwidths);


			var mousewheelevt=(/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel";
			if (document.attachEvent) 

			  document.attachEvent("on"+mousewheelevt, $.largeimg_layout.scrollwheel);  

			else if (document.addEventListener)
			  document.addEventListener(mousewheelevt, $.largeimg_layout.scrollwheel, false);
		},

		scrollwheel: function(event) {

			  var delta = event.detail ? event.detail * (-120) : event.wheelDelta
			  var scrollOffset = 30 * (delta / -120);

			  window.scrollBy(scrollOffset, 0);

			  event.preventDefault;
			  event.stopPropagation;
		}

	},

	$.fadenav_layout = {

		imagecount: 0,

		current: 1,

		init: function(){
			$.fadenav_layout.fadecontrols();
		},

		fadecontrols: function(){
			$('#fadenav_images').exposure({controlsTarget : '.fadenav_layout #controls', 
				showThumbnails : false,
				preloadBuffer: 5,
				onImage : function(image, imageData, thumb) {

						var hovered = $('.fadenav_layout .exposureWrapper').hasClass('exposureHover');

						// Fade out the previous image.

						$('.fadenav_layout .exposureWrapper > .fadenav_layout .exposureLastImage').stop().fadeOut(500, function() {

							$(this).remove();

						});

						

						// Fade in the current image.

						image.hide().stop().fadeIn(1000);

						

						var hasCaption = function() {

							return imageData.find('.caption').html().length > 0 || imageData.find('.extra').html().length > 0;

						}

						

						var showImageData = function() {

							imageData.stop().show().animate({bottom:0+'px'},{queue:false,duration:160});

						}

						var hoverOver = function() {

							$('.fadenav_layout .exposureWrapper').addClass('exposureHover');

							// Show image data as an overlay when image is hovered.

							var hasCpt = hasCaption();

							

							if (hasCpt) {

								showImageData.call();

							}

						};

						

						var hideImageData = function() {

							var imageDataBottom = -imageData.outerHeight();

							imageData.stop().show().animate({bottom:imageDataBottom+'px'},{queue:false,duration:160});

						}

						var hoverOut = function() { 

							$('.fadenav_layout .exposureWrapper').removeClass('exposureHover');

							// Hide image data on hover exit.

							if (hasCaption()) {

								hideImageData.call();

							}

						};

						

						$('.fadenav_layout .exposureWrapper').hover(hoverOver,hoverOut);

						imageData.hover(hoverOver,hoverOut);

												

						if (hovered) {

							if (hasCaption()) {

								showImageData.call();

							} else {

								hideImageData.call();	

							}	

						}

				}

			});

		}

	},

	$.smallthumb_layout = {

		init: function(){

			$.smallthumb_layout.hookthumbs();
			
			$.smallthumb_layout.slider()

		},

		hookthumbs: function(){

				$('#smallthumb_images').exposure({controlsTarget : '.smallthumb_layout #controls',

					controls : { prevNext : false, pageNumbers : false, firstLast : false },

					pageSize : 2000,
					preloadBuffer: 5,
					onThumb : function(thumb) {

						var li = thumb.parents('li');				

						var fadeTo = li.hasClass('active') ? 1 : 0.3;

						

						thumb.css({display : 'none', opacity : fadeTo}).stop().fadeIn(200);

						

						thumb.hover(function() { 

							thumb.fadeTo('fast',1); 

						}, function() { 

							li.not('.active').children('img').fadeTo('fast', 0.3); 

						});

					},

					onImage : function(image, imageData, thumb) {

						// Check if wrapped is hovered.

						var hovered = $('.smallthumb_layout .exposureWrapper').hasClass('exposureHover');

						

						// Fade out the previous image.

						$('.smallthumb_layout .exposureWrapper > .smallthumb_layout .exposureLastImage').stop().fadeOut(500, function() {

							$(this).remove();

						});

						

						// Fade in the current image.

						image.hide().stop().fadeIn(1000);

						

						var hasCaption = function() {

							return imageData.find('.caption').html().length > 0 || imageData.find('.extra').html().length > 0;

						}

						

						var showImageData = function() {

							imageData.stop().show().animate({bottom:0+'px'},{queue:false,duration:160});

						}

						var hoverOver = function() {

							$('.smallthumb_layout .exposureWrapper').addClass('exposureHover');

							// Show image data as an overlay when image is hovered.

							var hasCpt = hasCaption();

							

							if (hasCpt) {

								showImageData.call();

							}

						};

						

						var hideImageData = function() {

							var imageDataBottom = -imageData.outerHeight();

							imageData.stop().show().animate({bottom:imageDataBottom+'px'},{queue:false,duration:160});

						}

						var hoverOut = function() { 

							$('.smallthumb_layout .exposureWrapper').removeClass('exposureHover');

							// Hide image data on hover exit.

							if (hasCaption()) {

								hideImageData.call();

							}

						};

						

						$('.smallthumb_layout .exposureWrapper').hover(hoverOver,hoverOut);

						imageData.hover(hoverOver,hoverOut);

												

						if (hovered) {

							if (hasCaption()) {

								showImageData.call();

							} else {

								hideImageData.call();	

							}	

						}

		

						if ($.exposure.showThumbs && thumb && thumb.length) {

							thumb.parents('li').siblings().children('img.selected').stop().fadeTo(200, 0.7);			

							thumb.fadeTo('fast', 1).addClass('selected');

						}

					}

				});

		},
		slider: function(){
			var step = 9; 
			var current = 0; 
			var maximum = $('#small_thumbs_container ul li').size(); 
			var visible = 9; 
			var speed = 800; 
			var liSize = 74;
			var carousel_height = 64;
	 
	 
			var ulSize = liSize * maximum;   
			var divSize = 740;  
	 
			$('#small_thumbs_container ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");
	 
			$('#small_thumbs_container').css("width", divSize+"px").css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative"); 
	 
			$('.thumbsnext').click(function() { 
				if(current + step < 0 || current + step > maximum ) {return; }
				else {
					current = current + step;
					$('#small_thumbs_container ul').animate({left: -(liSize * current)}, speed, null);
				}
				return false;
			});
	 
			$('.thumbsprev').click(function() { 
				if(current - step < 0 || current - step > maximum - visible) {return; }
				else {
					current = current - step;
					$('#small_thumbs_container ul').animate({left: -(liSize * current)}, speed, null);
				}
				return false;
			});
			
		}

		

	},

	$.portrait_layout = {

		COLNUMBER : 2, // Minimum column number.
		COLMARGIN : 10, // Margin (in pixel) between columns/boxes.
		COLWIDTH : 254, // Fixed width of all columns.

		init: function(){

			//S$.portrait_layout.buildlayout();

			$(window).load(function() {
				$.portrait_layout.buildlayout();
			}).resize(function() {
				$.portrait_layout.buildlayout();
			});
			
			Shadowbox.init({
				troubleElements: ["select"]
			});

		},

		buildlayout: function(){

			var pointer = 0;

			var arr = [];

			var columns = Math.max($.portrait_layout.COLNUMBER, parseInt($('.portrait_layout').innerWidth() / ($.portrait_layout.COLWIDTH + $.portrait_layout.COLMARGIN)));



			$('.portrait_layout .box').css('position', 'absolute').css('width', $.portrait_layout.COLWIDTH  + 'px');

			$('.portrait_layout .box').each(function() {

				var tempLeft = (pointer * ($.portrait_layout.COLWIDTH + $.portrait_layout.COLMARGIN));

				$(this).css('left', tempLeft + 'px');

				var tempTop = 0;

				if (arr[pointer]) { tempTop = arr[pointer];	}

				$(this).css('top', tempTop + 'px');



				arr[pointer] = tempTop + $(this).outerHeight() + $.portrait_layout.COLMARGIN;

				pointer++;

				if (pointer === columns) { pointer = 0; }

			});

			

			$('.portrait_layout .box').hover(function() { 

				$(this).find("img").fadeTo('fast',0.2); 

				$(this).find(".description").fadeIn('fast');

			}, function() { 

				$(this).find(".description").fadeOut('fast');

				$(this).find("img").fadeTo('fast', 1); 

			});

		}

	}

})(jQuery);


