
	$(document).ready(function() {
		
		if ($('#intro').length) {		
			$('#intro').click(function() {
				$(this).stop(true).slideUp(700);
			}).delay(5000).slideUp(700);			
		}
		
		$("#searchQ").focus(function() {
			if ($(this).val() == 'Sök produktblad') {
				$(this).val('');
			}				
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).val('Sök produktblad');
			}
		});
		
		var scrollSpeed = 0;
		
		if ($('#news').length) {
			
			$("#news_uparrow").bind('click', function() {return false})
			$("#news_downarrow").bind('click', function() {return false})
			
			$("#news_uparrow").hide();
			
			$("#news_uparrow").mousedown(function(){
				scrollSpeed = 1;
				scrollNews();
			}).mouseup(function(){
				scrollSpeed = 0;
			}).mouseout(function(){
				scrollSpeed = 0;
			});
			
			$("#news_downarrow").mousedown(function(){
				scrollSpeed = -1;
				scrollNews();
			}).mouseup(function(){
				scrollSpeed = 0;
			}).mouseout(function(){
				scrollSpeed = 0;
			});
			
		}
		
		function scrollNews() {
		
			if (scrollSpeed != 0) {
				var currentHeight = $("#news_items").height();
				var currentTop = $("#news_items").position().top;
				var moveTo = currentTop + scrollSpeed;
				if (moveTo > 0) {
					moveTo = 0;
					$("#news_uparrow").fadeOut();
				}
				else {
					$("#news_uparrow").fadeIn();
				}
				if (moveTo < 0 - (currentHeight - 120)) {
					moveTo = 0 - (currentHeight - 120);
					$("#news_downarrow").fadeOut();
				}
				else {
					$("#news_downarrow").fadeIn();
				}
				$("#news_items").css("top", moveTo + "px");
				setTimeout(scrollNews, 10);
			}
		}
		
		$('.memory_game').click(function() {
			var width = 1025;
			var height = 832;
			
			var left = parseInt((screen.availWidth/2) - (width/2));
			var top = parseInt((screen.availHeight/2) - (height/2));			
						
			window.open("/memory/", "memory",
					"resizable=no,scrollbars=yes,status=yes,width=" 
					+ width + ",height=" + height + ",left=" + left + ",top=" + top			
			);			
			return false;
		});
		
		$('.parker_robot_link').click(function() {
			$('#startpage_flash').css('display', 'block');
			return false;
		});
					
		if ($('#categories').length) {
					
			$("#category_slider").scrollable({
					size: 1,
					items: '.cat',
					clickable: false,
					onSeek: function(event, i) {
						if (i > 0) {
							$('.prev span').text($('#slider_nav li:eq(' + (i-1) + ')').text());
							$('.prev').attr('href', $('#slider_nav li:eq(' + (i-1) + ') a').attr('href'));
							if ($('.prev span').height() > 25) $('.prev span').css('margin-top', '-6px');
							else $('.prev span').css('margin-top', '0');
						}
						if (i < $('#slider_nav li').length - 1) {
							$('.next span').text($('#slider_nav li:eq(' + (i+1) + ')').text());
							$('.next').attr('href', $('#slider_nav li:eq(' + (i+1) + ') a').attr('href'));
							if ($('.next span').height() > 25) $('.next span').css('margin-top', '-6px');
							else $('.next span').css('margin-top', '0');
						}
					}
				}
			).navigator({
					navi: "#slider_nav",			
					naviItem: 'a',			
					activeClass: 'current'
				}
			);
					
			$('a.prev, a.next', $('div.category_nav')).click(function() {
				$('div.info_box').hide();
			});
			
			$('div.product').each(function(i) {
				
				var product_id = $(this).attr('id').substr(8);
				var tooltip_id = '#box_' + product_id;
				
				$(this).tooltip({
					position: "center right", 
					tip: tooltip_id,
					effect: 'slide',
					oneInstance: true,
					offset: [-100, -15],
					onBeforeShow: function() {
						$('div.info_box').hide();
					},
					onBeforeHide: function() {
						return false;
					},
					events: {
						def: 'click,blur'
					}
				});
				
			});
			
		}
		
		if ($('#contacts').length) {
			$('div.addresses a').each(function(i) {
				
				var distr_id = $(this).attr('id').substr(6);
				var tooltip_id = '#box_' + distr_id;
				
				$(this).tooltip({
					position: "top right",
					tip: tooltip_id,
					effect: 'slide',
					offset: [0, 5],
					events: {
						def: 'click,blur'
					},
					onBeforeShow: function() {
						$('div.box:visible').hide()
					},
					onBeforeHide: function() {
						return false;
					}
				});
				
			});
		}
		
		if ($('#brands').length) {
			$('#content').css('height', 'auto');
		}
		
		if ($('#services').length) {
			$('#content').css('height', 'auto');
		}		
		
		if ($('#campaign').length) {
			if ($('#campaign div.text').height() + 20 > $('#content').height()) {
				$('#content').css('height', 'auto');
			}
		}
		
		if ($('#event').length) {
			if ($('#event').height() + 20 > $('#content').height()) {
				$('#content').css('height', 'auto');
			}
		}
		
		if ($('#productsheet').length) {
			if ($('#productsheet').height() + 20 > $('#content').height()) {
				$('#content').css('height', 'auto');
			}
		}
		
		if (jQuery().uniform) {
			$('#sel_campaigns').uniform();
		}
		
		$('#sel_campaigns').change(function() {
			var url = $(this).val();
			if (url != 0) {
				window.location = url; 
			}
			return false;
		});
				
		$('.kc_finder').click(function() {

			window.CKEDITOR = null;
			var $input = null;
			var tag_name = this.tagName.toLowerCase();
			
			if (tag_name == 'input') {
				$input = $(this);
			} else if (tag_name == 'a') {
				$input = $(this).prev('input');
			}
			
			if ($input == null) return;
			
			window.KCFinder = {
				callBack: function(value) {
					value = value.replace(parker.baseUrl, '').replace('app/webroot', '');
					$input.val(value);
				}
			};			
			
			var width = 900;
			var height = 600;
			
			var left = parseInt((screen.availWidth/2) - (width/2));
			var top = parseInt((screen.availHeight/2) - (height/2));
			
			var browser = window.open(parker.baseUrl + 'js/kcfinder/browse.php', 'kcfinder',
					'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
					'resizable=1, scrollbars=0, top='+top+', left='+left+', ' +
					'width='+width+', height=' + height
			);
			browser.focus();
		});
		
		if (jQuery().ckeditor) {		
			
			$('.ck_editor').ckeditor(function() {}, {
				width: 600,
				resize_minWidth: 550,
				resize_maxWidth: 600,
				forcePasteAsPlainText: true,
				disableNativeSpellChecker: true,
				scayt_autoStartup: false,
				entities: false,
				toolbar :
					[
					 	[ 'Bold', 'Italic', 'Format', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-', 'Source' ]
					]
			});
			
		}		
		
		$('a.brands').cycle();
			
		Cufon.replace('div.intro_text p', {'fontFamily': 'Helvetica Neue'});
		Cufon.replace('#info_boxes h4', {'fontFamily': 'Helvetica Neue'});
		Cufon.replace('#info_boxes div.arrow a', {'fontFamily': 'Helvetica Neue'});
		
	});
