var search_input;
var riders_animation;

$(document).ready(function(){
	search_input = $('#s');
	if (search_input.length) {
		search_input.val('Keyword');
		search_input.focus(function(){
			if (search_input.val() == 'Keyword') {
				search_input.val('');
			}
		});
		search_input.blur(function(){
			if (search_input.val() == '') {
				search_input.val('Keyword');
			}
		});
	}
	
	if ($('#new_comment').length) {
		author = $('#author');
		author.val('Your name');
		author.focus(function(){
			if (author.val() == 'Your name') {
				author.val('');
			}
		});
		author.blur(function(){
			if (author.val() == '') {
				author.val('Your name');
			}
		});
		
		email = $('#email');
		email.val('Your e-mail');
		email.focus(function(){
			if (email.val() == 'Your e-mail') {
				email.val('');
			}
		});
		email.blur(function(){
			if (email.val() == '') {
				email.val('Your e-mail');
			}
		});
		
		comment = $('#comment');
		comment.val('Comment');
		comment.focus(function(){
			if (comment.val() == 'Comment') {
				comment.val('');
			}
		});
		comment.blur(function(){
			if (comment.val() == '') {
				comment.val('Comment');
			}
		});
	}
	
	riders_animation = $('#riders_animation');
	if (riders_animation.length) {
		swfobject.embedSWF(template_dir+'images/riders_home.swf', 'riders_animation', '1009', '381', '9.0.0', template_dir+'images/expressInstall.swf', {}, {wmode: 'transparent'});
	}
	
	if (typeof(doLoadLocator) == 'function') {
		doLoadLocator();
	}
	
	if (typeof(doLoadVideo) == 'function') {
		doLoadVideo();
	}
});

function submitComment() {
	$('#comments').find('input, textarea').removeClass('error');
	
	var author = jQuery.trim($('#author').val());
	var email = jQuery.trim($('#email').val());
	var comment = jQuery.trim($('#comment').val());
	
	if (author != 'Your name' && author != '' && email != 'Your e-mail' && email != '' && comment != 'Comment' && comment != '') {
		$('#commentform').submit();
	} else {
		if (author == 'Your name' || author == '') {
			$('#author').addClass('error');
		}
		if (email == 'Your e-mail' || email == '') {
			$('#email').addClass('error');
		}
		if (comment == 'Comment' || comment == '') {
			$('#comment').addClass('error');
		}
	}
}

function loadLocator(y, x, url, home) {
	if ($('#locator_flash').length) {
		var flashvars = {
				locatorY: y,
				locatorX: x,
				theUrl: url
			};
		var width = '320';
		var height = '320';
		if (home) {
			width = '290';
			height = '265';
		}
		swfobject.embedSWF(template_dir+'images/locator.swf', 'locator_flash', width, height, '9.0.0', template_dir+'images/expressInstall.swf', flashvars, {wmode: 'transparent'});
	}
}

function videoHome(el, hires, lores, preview) {
	loadVideo(hires, lores, preview);
	$('#video_home li.active').removeClass('active');
	$('#'+el).addClass('active');
}

function loadVideo(hires, lores, preview) {
	var player = $('#player');
	var flashvars = {
			videoSourceHd: hires,
			videoSourceLd: lores,
			imageSource: preview
		};
	var params = {
			menu: 'false',
			allowfullscreen: 'true'
		};
	swfobject.embedSWF(template_dir+'images/Flvplayer.swf', 'player', '564', '317', '9.0.0', template_dir+'images/expressInstall.swf', flashvars, params);
}