$(document).ready( function(){
		if($.cookie("style")!=null){
			resize(0);
		}else{
			$('#gallery ul li .imgBox img').css('visibility', 'visible');
		}
		
		$( "#sliderPath" ).slider({
			value:$.cookie("style"),
			min: 0,
			max: 100,
			step: 50,
			slide: function( event, ui ) {
				var $style = ui.value;
				$.cookie("style",$style, {expires: 365, path: '/'});
				//window.location.reload(); // Uncomment this line if thumb change is wanted with page refresh
				resize(1);// Keep this if thumbs resize is wanted on the fly, with NO page refresh
			}
		});
});

function resize(i){
	if(i==1){
		$( "#gallery").hide();
	}
	if($.cookie("style") == '0') {
		$( "#gallery").removeClass();
		$( "#gallery").addClass('threeperrow');
		$( "#gallery").fadeIn('slow'); 
		$( "#gallery .imgBox img").each(function(){
			var oldsrc = $(this).attr('src');
			var imgsrcparts = new Array();
			imgsrcparts = $(this).attr('src').split('-');
			var newsrc= oldsrc.replace(imgsrcparts[2],'204x153.png');
			$(this).attr('src','');
			$(this).attr('src',newsrc);
			$(this).attr('width','');
			$(this).attr('width','204');
			$(this).attr('height','');
			$(this).attr('height','153');
			$(this).css('visibility', 'visible');			  
		});
	}
	if($.cookie("style")=='50'){
		$( "#gallery").removeClass();
		$( "#gallery").addClass('twoperrow');
		$( "#gallery").fadeIn('slow');
		$( "#gallery .imgBox img").each(function(){
			var oldsrc = $(this).attr('src');
			var imgsrcparts = new Array();
			imgsrcparts = $(this).attr('src').split('-');
			var newsrc= oldsrc.replace(imgsrcparts[2],'324x243.png');
			$(this).attr('src','');
			$(this).attr('src',newsrc);
			$(this).attr('width','');
			$(this).attr('width','324');
			$(this).attr('height','');
			$(this).attr('height','243');
			$(this).css('visibility', 'visible');
		});
	}
	if($.cookie("style")=='100'){
		$( "#gallery").removeClass();
		$( "#gallery").addClass('oneperrow');	
		$( "#gallery").fadeIn('slow');
		$( "#gallery .imgBox img").each(function(){
			var oldsrc = $(this).attr('src');
			var imgsrcparts = new Array();
			imgsrcparts = $(this).attr('src').split('-');
			var newsrc= oldsrc.replace(imgsrcparts[2],'684x513.png');
			$(this).attr('src','');
			$(this).attr('src',newsrc);
			$(this).attr('width','');
			$(this).attr('width','684');
			$(this).attr('height','');
			$(this).attr('height','513');
			$(this).css('visibility', 'visible');
		});
	}
		
}
