var mouseX = 1;
var mouseY = 1;
var voteHref = '';

document.onmousemove = getMouseXY;
google.load("jquery", "1.4.2");
google.load("swfobject", "2.2");

google.setOnLoadCallback(function() {									  
	flashObjects();	
	animObjects();
	$('a.clickForMoto').click(function(){motoShow(this);return false;});
	$('a#next').click(function(){motoPage(this);return false;});	
	$('a#prev').click(function(){motoPage(this);return false;});		
});

function motoShow(that) {
	var src=that.href;
	$('#motoshow img').fadeOut(250, function(){$('#motoshow').html('<img src="'+src+'" alt="" title="'+that.rel+'" width="495" height="410" onclick="motoVote(this);" />');$('#motoshow img').fadeIn(250);});
}

function motoPage(that) {
	$('#trailers').load('http://www.pimpmymoto.fi/motoscroll.php?pagin='+that.rel);
}

function motoVote(that) {
	voteHref = that.title;	
	$('#voteLayer').fadeIn(500);
}

function motoVoteThat(vote) {
	$.post("http://www.pimpmymoto.fi/votesave.php", { id: voteHref, vote: vote } );	
	$('#voteLayer').fadeOut(500, function(){$('#thanksLayer').fadeIn(500, function(){ setTimeout("$('#thanksLayer').fadeOut(500);",1000); });});	
}


function animObjects(that) {
	$('#layerMenu').css('left',205+'px');	
	$('#layerMenu').animate({left:0+'px'},500);	
	$('#layerOtherItems').css('right',205+'px');	
	$('#layerOtherItems').animate({right:15+'px'},500);
}

function flashObjects() {
	var flashvars = {};
	var params = {};
	var attributes = {};
	
	//Logo
	attributes.id = "logo";
	params.wmode = "transparent"; 
	swfobject.embedSWF("/wp-content/themes/pimpmymoto/flash/logo.swf", "logo", "248", "112", "9.0.0", false, flashvars, params, attributes);	
	//Homepage
	attributes.id = "homeflash";
	swfobject.embedSWF("/wp-content/themes/pimpmymoto/flash/home.swf", "homeflash", "505", "420", "9.0.0", false, flashvars, params, attributes);	
	//Footer
	attributes.id = "footerflash";
	swfobject.embedSWF("/wp-content/themes/pimpmymoto/flash/footer.swf", "footerflash", "520", "50", "9.0.0", false, flashvars, params, attributes);		
	//TuneMoto Game
	attributes.id = "tunemoto";
	swfobject.embedSWF("/moto.swf", "tunemoto", "495", "410", "9.0.0", false, flashvars, params, attributes);	
	//GameMoto Game
	attributes.id = "gamemoto";
	swfobject.embedSWF("/main.swf", "gamemoto", "495", "410", "9.0.0", false, flashvars, params, attributes);	
	//Images SWF
	attributes.id = "imagesvid";
	swfobject.embedSWF("/traileri1.swf", "imagesvid", "480", "295", "9.0.0", false, flashvars, params, attributes);		
}

function getMouseXY(e) {
	try {
		if (!e) var e = window.event||window.Event;
		if('undefined'!=typeof e.pageX) {
			mouseX = e.pageX;
			mouseY = e.pageY;
		} else {
			mouseX = e.clientX + document.body.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop;
		}		
	} catch(err) {
		/* Do Nothing And Wonder What's Happening */
	}
}

