$(document).ready(function(){
	$('.lastnews .title').click(function(){
		var link = $(this).parent().find('a').attr('href');
		location.href = link;
	});
	
    $('.linkThis:not(:has(input[type="button"]))').click(function(e) {
        e.stopPropagation();
        e.preventDefault();
        
        var link = $(this).find('a').attr('href');
        location.href = link;
        
        return false;
    });
    
    $('.linkThis:has(input[type="button"]) img').click(function(e) {
        e.stopPropagation();
        e.preventDefault();
        
        location.href = $(this).parent().find('a').attr('href');
        
        return false;
    });
	
/*	$('.linkThis').click(function(e){
        var link = $(this).find('a').attr('href');
		location.href = link;
		return false;
	});*/
	
	$('.loop .item .title').click(function(){
		var link = $(this).parent().find('a').attr('href');
		location.href = link;
		return false;
	});
	
	$('.topMenu li').click(function(){
		location.href = $(this).find('a').attr('href');
		return false;
	});
	
	$('.preamble').parent().addClass('preamble');
	
	if($('img.picshadow').length > 0){
		var div = $('<div/>');
		$(div).addClass('gallery picshadow');
		$(div).css('width', function(){
			return $('img.picshadow').width() + 40;
		});
		$('img.picshadow').wrap(div).wrap('<div class="padding" />');
		$('.gallery.picshadow').append('<div class="corner ne" />');
		$('.gallery.picshadow').append('<div class="corner se" />');
		$('.gallery.picshadow').append('<div class="corner sw" />');
		$('.gallery.picshadow').append('<div class="corner nw" />');
	}
	
	$('ul.sorter').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	

		
});

function blurThis(element, value){
	if($(element).attr('value') == '')
		$(element).attr('value', value);
}
function clearValue(element, value){
	if($(element).attr('value') == value)
		$(element).attr('value', '');
}
var moreProductsIndex = 1;
function changePage(){
	moreProductsIndex = arguments[0];
	$('.pagingNavigation a.active').removeClass('active');
	$('.pagingNavigation a:nth-child('+ (moreProductsIndex + 1) +')').addClass('active');
	if(moreProductsIndex >= (moreProductsPages - 1))
		$('.pagingNavigation a.nextButton').hide();
	if(moreProductsIndex >= 1)
		$('.pagingNavigation a.prevButton').show();
	if(moreProductsIndex <= 1)
		$('.pagingNavigation a.prevButton').hide();
	if(moreProductsIndex < moreProductsPages)
		$('.pagingNavigation a.nextButton').show();
	slidePaging();
}
function showAllOnProductPage() {
    
	var distance = $('.moreProducts .item').length,
        height   = $('.moreProducts .holder .item').first().height();
	
	if (distance % 3 !== 0) {
	   distance = distance + (distance % 3);
	}

    var height = (height * distance / 3) + height;
    
    $('.slider').css('top', '0');
    $('.pagingNavigation').css('display', 'none');
    $('.moreProducts').animate({'height': height + 'px'});
    
}
function nextPage(){
	moreProductsIndex++;
	$('.pagingNavigation a.active').removeClass('active').next().addClass('active');
	if(moreProductsIndex >= moreProductsPages)
		$('.pagingNavigation a.nextButton').hide();
	if(moreProductsIndex == 2)
		$('.pagingNavigation a.prevButton').show();
	slidePaging();
}
function prevPage(){
	moreProductsIndex--;
	$('.pagingNavigation a.active').removeClass('active').prev().addClass('active');
	if(moreProductsIndex <= 1)
		$('.pagingNavigation a.prevButton').hide();
	if(moreProductsIndex < moreProductsPages)
		$('.pagingNavigation a.nextButton').show();
	slidePaging();
}
function slidePaging(){
	var distance = -460;
	if($('.buyMode').length > 0)
		distance = -580;
		
	$('.moreProducts .slider').animate({'top': ((moreProductsIndex - 1) * distance) + 'px'}, 300);
}
