
$(document).ready(function () {


		// Slashes manager
		//$('.add-slashes,.active-1,.active-2').append('<span class="slashes"> //</span>');
		$('.CMSListMenuLinkHighlighted, .add-slashes').not('#main-menu ul ul li a.CMSListMenuLinkHighlighted').append('<span class="slashes"> //</span>');

		// Add "last" class to different elements
		$('.page-nav li:last').addClass('last');
		//$('.popup:nth-child(3n)').addClass('last');
		
		$('.products').each(function () { 
			if($(this).parents().hasClass('wide')){
				$('.products li:nth-child(2n)').addClass('last');		
			} else {
				$('.products li:nth-child(3n)').addClass('last');		
			}						  
		});
		
		// Activate autocolumn.js
		$('.columnize').columnize({width:160});  
		
		// Add onfocus class to active input field
		$('.generic-form input').not('#submit').focus(function(){
			$(this).parent('p').addClass('onfocus');
		});
		$('.generic-form input').blur(function(){
			$(this).parent('p').removeClass('onfocus');
		});
				
		// Generate SlideUpPanels
		jQuery.fn.slideUpPanels = function() {
			
			var counter = 0;
			var position = 0;
			$('.popup-list .popup').each(function(){
				$(this).css({
				'position' : 'absolute',
				'bottom' : '0',
				'left' : position+'px'
				});
				counter = counter+1;
				position = position+185;
				if ($(this).hasClass('last')){
					position =  0;
				};
			});
			
			$('.popup .hide').hide();
			$('.popup').hover(function(){
				$(this).find('.crop-image').addClass('expanded');
				$(this).find('.hide').stop(true, true).slideDown('normal');	
				}, function(){
				$(this).find('.hide').slideUp('normal');
				$(this).find('.expanded').removeClass('expanded');	
			});					
		};
		
		$('.popup-list').slideUpPanels();
		
		// hide popopen menus
		$('.popopen').each(function() {
			$(this).children('ul').each(function () {
				$(this).css({ 'display': 'none' });
			});
			$(this).children('a').toggle(
				function() {
					$(this).parent().children('ul').each(function () {
						$(this).css({ 'display': 'block' });
					});
					$(this).addClass('CMSListMenuLinkHighlighted');
				},
				function() {
					$(this).parent().children('ul').each(function () {
						$(this).css({ 'display': 'none' });
					});
					$(this).removeClass('CMSListMenuLinkHighlighted');
				}
			);
		});
		
		// open the categories menu first up
		$('.popopen').not('ul li .popopen').children('a').click();
		
		
		var screenHeight = $(window).height();
		//alert(screenHeight);
		$('#splash-image').css({
				'height' : screenHeight-234
		});
		
		// product images
		$("a[rel='productimage'], a[rel='mainimage'], a[rel='mainimagelink']").colorbox({ transition:"elastic", photo:true });
		
});

