﻿if(!ricoh){ var ricoh = {}; }
$(document).ready(function () {
	ricoh.Search();
	if($('.slideshow').length > 0) ricoh.Slideshow();
	if($('.product').length > 0) ricoh.equalHeight($('.product'));
});

ricoh.Slideshow = function(){

	$('.slideshow').each(function(i) {
        $(this).wrap('<div class="image-slideshow" />');
        $(this).after('<a href="#" class="prev-slide prev' + i + '">Föregående bild</a>');
        $(this).after('<a href="#" class="next-slide next' + i + '">Nästa bild</a>');
        $(this).cycle({
			fx:     'fade',
			speed: 	'fast',
			timeout: 0,
			next:   '.next' + i,
			prev:   '.prev' + i
		});
		
		if ($(this).children().length === 1) {
			$(this).find('.slide:first').show();
			$('.prev-slide, .next-slide').hide();
		}
    });
    
};

ricoh.equalHeight = function(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
};

ricoh.Search = function() {
	$('.search-form input[type="text"]').each(function(i) {
		var input = $(this);
		input.val(input.attr('title'));
		input.addClass('watermark');

		input.focus(function() {
			if ($(this).hasClass('watermark'))
				$(this).val('').removeClass('watermark');
		});

		input.blur(function() {
			if ('' == $(this).val())
				$(this).val($(this).attr('title')).addClass('watermark');
		});
	});
};
