$(document).ready(function() {
	
	/* disable context menu */
	
	$(this).bind("contextmenu", function(e) {
		e.preventDefault();
	});
	
	/* disable image dragging */
	
	$("img").mousedown(function() {
		return false;
	})
	
	/* home start */
	
	$('#home_images').jkdGallery({
		overflow:     {
			x: false
		},
		adjust:       {
			height: -($('#header').height() + $('#footer').height())
		},
		showPrev:     false,
		showNext:     false,
		showNav:      false,
		resize:       true,
		autoLoop:     true,
		afterLoad: function(gallery) {
			$(gallery).css('position', 'absolute');
		}
	});
	
	$('#home_tables').jkdGallery({
		overflow:     {
			x: false
		},
		adjust:       {
			height: -($('#header').height() + $('#footer').height())
		},
		showPrev:     false,
		showNext:     false,
		showNav:      false,
		resize:       true,
		autoLoop:     true,
		afterLoad: function(gallery) {
			$(gallery).prev().find('.jkdGallery-first').bind('load', function() {
				$item = $(this);
				
				$(gallery).children('.jkdGallery-items').children().each(function() {
					$(this).width($item.width());
					$(this).height($item.height());
					$(this).css('left', $item.css('left'));
					$(this).css('top', $item.css('top'));
				});
			});
		},
		afterResize: function(gallery) {
			var $item = $(gallery).prev().children('.jkdGallery-items').find(':visible');
			
			$(gallery).children('.jkdGallery-items').children().each(function() {
				$(this).width($item.width());
				$(this).height($item.height());
				$(this).css('left', $item.css('left'));
				$(this).css('top', $item.css('top'));
			});
		}
	});
	
	/* home end */
	
	/* product list start */
	
	$('#banner').cycle({
		before: function() {
			$(this).css('left', '50%');
		}
	});
	
	/* product list end */
	
	/* product details start */
	
	$('.product_color_box img').each(function() {
		$this = $(this);
		$this.qtip({
			content: '<div class="product_color_tooltip">'
					+'<img src="' + $this.attr('src') + '" alt="tooltip" />'
					+'<span><strong>F&auml;rg</strong>: ' + $this.attr('alt') + '</span>'
					+'</div>',
			position: {
				corner: {
					target:  'topMiddle',
					tooltip: 'bottomMiddle'
				},
				adjust: {
					y: 3
				}
			},
			style: {
				width:  177,
				height: 149,
				background: 'transparent',
				'background-image': 'url(' + base_url + '/images/css/tooltip_bg.png)',
				'background-repeat': 'no-repeat',
				padding: 0,
				border: 'none'
			},
			hide: {
				fixed: true
			}
		});
	});
	
	$('#image_row a').click(function() {
		$('#product_image img').attr('src', $(this).children('img').attr('src'));
		return false;
	});
	
	/* product details end */
	
	/* inspiration start */
	
	$('#inspiration').jkdGallery({
		overflow:     {
			x: false
		},
		adjust:       {
			height: -$('#header').height()
		},
		prevText:     '',
		nextText:     '',
		resize:       true,
		autoLoop:     true,
		pauseOnHover: true
	});
	
	/* inspiration end */
	
	/* footer start */
	
	$('#newsletter_input').focus(function() {
		$(this).removeAttr('style');
		if ($(this).val() == 'SKRIV DIN EPOST H\u00C4R' || $(this).val() == 'E-post ogiltig' || $(this).val() == 'E-post redan registrerad') {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val('SKRIV DIN EPOST H\u00C4R');
		}
	});
	
	$('#newsletter_form').submit(function() {
		$('#newsletter_submit').attr('disabled', 'disabled');
		$.ajax({
			type: 'POST',
			url: site_url + 'home/newsletter',
			data: 'email=' + $('#newsletter_input').val(),
			success: function(resp) {
				$('#newsletter_input').val(resp);
				if (resp == 'E-post tillägd') {
					$('#newsletter_input').attr('readonly', 'readonly');
				} else {
					$('#newsletter_input').css('color', '#DD0000');
					$('#newsletter_submit').removeAttr('disabled');
				}
			}
		});
		return false;
	});
	
	/* footer end */
});
