jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};
$(function(){
		   
	Cufon.replace('h1,.breadcrumb,h4,.spotlight h3,.key_peoples li blockquote q, .body .inner-content h3', {fontFamily: 'Glypha', hover:'true'});
	
	$('A[href$=pdf]').attr('target','_blank');
	if($('.pages a').size()==0){
		$('.pages span').remove();
	}
	$('.advanced_search_form select').sSelect();
	
	$('.advanced_search_form .options #categories_all,.advanced_search_form .options #finishes_all').change(function(){
		if(!$(this).is(':checked')){
			$(this).closest('.options').find(':checkbox').removeAttr('checked');
		}
		else{
			$(this).closest('.options').find(':checkbox').attr('checked','checked');
		}
	})
	
	$('.advanced_search_form').submit(function(){
		var categories=[];
		$(this).find('.categories :checkbox:checked').each(function(){
			categories.push($(this).val());
		});
		
		$(this).find('input[name="ProductCategory"]').val(categories.join(","));
		
		var finishes=[];
		$(this).find('.finishes :checkbox:checked').each(function(){
			finishes.push($(this).val())
		});
		
		$(this).find('input[name="TagsFinish"]').val(finishes.join(","));
	})
	
	$('.spotlight_list .item:nth-child(3n)').addClass('last');

	
	$('.products_list .item.wide:nth-child(2n)').addClass('last');
	var i=1;
	$('.products_list .item').not('.wide').each(function(){
		if(i%4==0){
			$(this).addClass('last');
		}
		i++;
	});
	
	if($('.single_column').size()>0){
		$('.left_column').remove();
		$('.wrapper').addClass('no_background');
	}
	
	$('.map_link').click(function(){
		$('.right_column iframe').attr('src',$(this).attr('href'));
		return false;
	});
	
	$('img[src*="btn_"],input[src*="btn_"],a[class*="btn"]').hover(function(){
		$(this).fadeTo('fast',0.5);
	},function(){
		$(this).fadeTo('fast',1);	
	})
	
	$('.product_thumbs img').each(function(){
		var src=$(this).attr('src').replace('small/','detailed/');
		$(this).hover(function(){window.imgsrc=$('.big_image').attr('src');$('.big_image').attr('src',src);},function(){$('.big_image').attr('src',window.imgsrc);});
	});
	
	$('.search_form .text').autotip({'text':'Search'});
	
	
	$('.details .thumbs a[rel!=]').hover(
	function(){
		window.imgsrc=$('.details .image>img').attr('src');
		$('.details .image>img').attr('src',$(this).attr('rel'));
	},
	function(){
		$('.details .image>img').attr('src',window.imgsrc);	
	});
	
	
	$('.single_column table td img[src*=about_us]').hover(function(){
		$(this).attr('src',$(this).attr('src').replace('.jpg','_over.jpg'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace('_over.jpg','.jpg'));
	})
	
	if($('.single_column').size()>0){
		$('body').append('<iframe id="preloader" src="preloader.html"></iframe>');
	}
	
	$('A.wishlist').click(function(){
		var wishlist=$.cookie('wishlist');
		if(wishlist==null) wishlist='';
		var id=$(this).attr('rel');
		var post='id='+id+'&action=add';
		$.post($('base').attr('href')+'wishlist-ajax',post,function(data){
			if(data.indexOf('done')!=-1){
				alert('This product has been added to your wishlist');
			}
		},'text');
		return false;
	});
	
	$('.products_list .item A.remove').click(function(){
		var item=$(this).parent();
		var id=$(this).attr('rel');
		var post='id='+id+'&action=remove';
		$.post($('base').attr('href')+'wishlist-ajax',post,function(data){
			if(data.indexOf('done')!=-1){
				$(item).remove();
			}
		},'text');
		
		return false;
	})
	
	//adding truncator for the hidden copy
	$('.seo_copy').truncate({max_length: 270});
	
	
	$(".img_slider ul li").live('click',function(){
		$("div.panes div:first").hide();
	});
	
	if($(".img_slider").size()>0){	
		$(".img_slider ul").tabs("div.panes div.pane");
		$(".img_slider").jScrollPane({showArrows: false, scrollbarWidth: 0, scrollbarMargin: 0});
	}
	
	
});
