$(document).ready(function() {

	$.ajaxSetup({cache: false})//disable caching on .load()

	$("#thumbs li:first-child a").addClass('current');
	
	function magnifyPro() {
		$('a[rel*=magnify]').magnify();
	};

	magnifyPro();

	showProduct();

	function showProduct() {
		$('#thumbs a').click(function() {
			if($(this).attr('class') == 'current') {
				return false;
			} else {
//				$('html').animate({scrollTop:0}, 'medium'); 
	
				$('#thumbs a').removeClass('current');
				$(this).addClass('current');		
				
				$("#target").html('<img src="/wp-content/themes/cm/images/content-load.gif" class="loading" alt="" />');
				var url = $(this).attr('href');
				$('#target').load(url, function() {
					$("#dio-sensor, #dio-lens").remove();
					magnifyPro();
				});
				return false;
			}
		});
	};

	$('#pagination a').click(function() {
		if($(this).attr('class') == 'current') {
			return false;
		} else {
			
			var current = $('#pagination a.current').html();
			
			if($(this).html() > current) {
				var left = '-661';
			} else {
				var left = '661';
			}						
			var url = $(this).attr('href') + " #thumbs ul";			
			$("#thumbs ul").animate({left: left}, 500, function() {
				$("#thumbs").html('<img src="/wp-content/themes/cm/images/thumbs-load.gif" class="loading" alt="" />');
				$('#thumbs').load(url, function() {
					showProduct();	
				});				
			});			
			
			$('#pagination a').removeClass('current');
			$(this).addClass('current');
			
			//$("#thumbs").html('loading');

			return false;	
		}
	});

        if ($.browser.msie && $.browser.version < 7) return;
        
        $('#cats li')
            .removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(450, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(450, 0);
                    });
                });
        $('#footer li')
            .removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(450, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(450, 0);
                    });
                });   
			
 	
});

//newsletter
function doClear(theText) {
	if (theText.value == theText.defaultValue) {
         theText.value = ""
	}
}
