
swfobject.registerObject("kok", "9.0.0");

var loop = true;
var move;

function moveIt(position, offset)
{
	position+=offset;
	if(position <= -(1305-960) || position >= 0) {
		return false;
	}	
	jQuery('#wrap-wrap').css('left', position+'px');
	move = setTimeout("moveIt("+position+","+offset+")",10);
}
var current_turn = 1;

function get_new_pos(x, y){
	if(x == -239){
		if(current_turn == 1){
			return "-478px 0px";
		}else {
			return "0px 0px";
		}
	}else{
		if(x==0){
			current_turn = 1;
		}else {
			current_turn = -1;
		}
		return "-239px 0px";
	}

}

var show_flash_text = function(number){
	if(window.document.thumb === undefined){
		return null;
	}

	window.document.thumb.style.display='';
	setTimeout('window.document.thumb.setText'+number+'()',1500);
	setTimeout('window.document.thumb.style.display=\'none\'',5000)
}

var desktop_items = new Array();
desktop_items['default'] = 0;
desktop_items['iphone'] = 2400;
desktop_items['laptop'] = 3000;
desktop_items['screen'] = 3600;
desktop_items['notepad'] = 4200;

var desktop_zooms = new Array();
desktop_zooms['screen'] = 1800;
desktop_zooms['laptop'] = 1200;
desktop_zooms['iphone'] = 600;


jQuery(document).ready(function() {


	jQuery('#command').submit(
		function() {
			var input = jQuery('input').val();
			jQuery('input').val('_');
			var two = input.split(' ');
			switch(two[0]) {
				case '_muu':
					alert('Kossan säger MUUU!!!');
					break;

				case '_go':
					if(two[1] == 'back') {
						history.go(-1);
					}
					jQuery('#empty').fancybox( { 'type' : 'iframe', 'href' : 'proxy.php?url='+two[1], 'height' : 500, 'width' : 883 } ).trigger('click');
					break;

				case '_zombie':
					jQuery('#empty').fancybox( { 'type' : 'ajax', 'href' : '/zombie.php', 'height' : 500, 'width' : 883 } ).trigger('click');
					break;

				case '_help':
				jQuery('#empty').fancybox( { 'type' : 'ajax', 'href' : '/help.php', 'height' : 500, 'width' : 883 } ).trigger('click');

			}
			jQuery(this).blur();

			return false;
		}
	);

	jQuery('#customers').click(
		function() {
			window.location = '/customers';
		}
	);

	jQuery('#no').click(
		function() {
			window.location = '/history';
		}
	);

	jQuery('#right').hover(
		function() {
			loop = true;
			var position = jQuery('#wrap-wrap').position().left;
			moveIt(position, -4);
		}, 
		function() {
			clearTimeout(move);
		}
	);

	jQuery('#left').hover(
		function() {
			loop = true;
			var position = jQuery('#wrap-wrap').position().left;
			moveIt(position, 4);
		}, 
		function() {
			clearTimeout(move);
		}
	);

	jQuery('#hitzone').hover(
		function() {
			jQuery('#splash_content').css('background-position', 'bottom left');
		},
		function() {
			jQuery('#splash_content').css('background-position', 'top left');
		}
	);

	jQuery('#hitzone').click(
		function() {
			jQuery('#splash').remove();
		}
	);


	//Removes title on easteregg
	$("#easteregg").fancybox({'titleShow':false, 'type':'swf', 'href': 'http://files.freeonlinegames.com/games/sharkattackMB/sharkattack.swf'});


	//Screen hover
	/*
	default: 0
	iphone: 600
	laptop: 1200
	screen: 1800
	*/


	$("#screen, #iphone, #laptop").hover(
		function(){
			var id = $(this).attr('id');
			$("#desktop").css("backgroundPosition", "0px "+desktop_items[id]+"px");
		},
		function(){
			$("#desktop").css("backgroundPosition", "0px "+desktop_items['default']+"px");
		}		    
	);

	$("#screen, #iphone, #laptop").click(function(){
		var id = $(this).attr('id');

		$('#desktop').fadeOut('normal', function(){
			$('#desktop').css('backgroundPosition', "0px "+desktop_zooms[id]+"px");
			$('#desktop').fadeIn('normal', function(){
				$.ajax({ 
					url: "/includes/"+id+".php", 
					success: function(data) {
						$('#desktop').fadeOut('fast', function(){
							$('#desktop').replaceWith(data);
							$('#'+id+'_closeup').fadeIn('fast');

							if(id == "screen"){
								show_flash_text(3);
							}else if(id == "laptop"){
								show_flash_text(2);
							}else if(id == "iphone"){
								show_flash_text(4);
							}
						});
					}
				});
			});
		});
	});
});

	$(window).load(function(){
		show_flash_text(1);
	});

