var SpaceRocket = {};


SpaceRocket.main = function() {
	var SWF_VERSION = '10.0.0';
	// Google Analytics: UA-10299905-1");
	
	//window.resizeTo(1024, 768);
	
	SpaceRocket.onSearchInit();
	
	
	SpaceRocket.roundImages([
		'.wpcf7-captcha-captcha-quote'
	]);
	
	
	if (swfobject.hasFlashPlayerVersion(SWF_VERSION)) {
		
		// H1 SWF FONT
		var title = jQuery('h1').html();
		jQuery('h1').html('<div id="swf-h1">' + title + '</div>');
		swfobject.embedSWF('/wp-content/themes/spacerocket/swf/h1.swf', 'swf-h1', '100%', '50', SWF_VERSION, false, {h1:title}, {bgcolor:'#ffffff', scale:'noscale', salign:'tl', menu:'false', wmode:'transparent'});
				
		// phone animation
		swfobject.embedSWF('/wp-content/themes/spacerocket/swf/phone.swf', 'phone-swf', '175', '25', SWF_VERSION, false, false, {bgcolor:'#ffffff', scale:'noscale', salign:'tl', menu:'false', wmode:'transparent'});
			
		// game page
		if(location.href.indexOf('game') != -1) {
			swfobject.embedSWF('/wp-content/themes/spacerocket/swf/slider.swf', 'game-swf', '215', '170', SWF_VERSION, false, {isPage:'true'}, {bgcolor:'#ffffff', scale:'noscale', salign:'tl', menu:'false', wmode:'transparent'});
		}
		
		// header
		if (swfobject.hasFlashPlayerVersion(SWF_VERSION)) {
			var slug = location.href;
			slug = slug.substring(slug.indexOf('.uk/') + 4);
			slug = slug.substring(0, slug.indexOf('/'));
			if(slug == '') {
				slug = 'welcome';
			}
			swfobject.embedSWF('/wp-content/themes/spacerocket/swf/header/' + slug + '.swf', 'swf-header', '675', '220', SWF_VERSION, false, {isPage:'true'}, {bgcolor:'#ffffff', scale:'noscale', salign:'tl', menu:'false', wmode:'transparent'});
		}		
		
	}
	
	
	// Preload common images
	SpaceRocket.preloadImages([
		'/wp-content/themes/spacerocket/images/enquiry-bg-over.png',
		'/wp-content/themes/spacerocket/images/logo-over.png',
		'/wp-content/themes/spacerocket/images/search-icon-hover.png'
	]);
};


// cross browser round images
SpaceRocket.roundImages = function(images) {
	for(var i = 0; i < images.length; i++) {
		jQuery(images[i]).wrap(function(){
			var r = '<div class="' + jQuery(this).attr('class') + '" style="background:url(' + jQuery(this).attr('src') + ') no-repeat center center; width: ' + jQuery(this).width() + 'px; height: ' + jQuery(this).height() + 'px;"/>';
			jQuery(this).removeClass(images[i]);
			jQuery(this).addClass('hiddenimage');
			return r;
		});
	}
};


// Site Search Form
SpaceRocket.onSearchInit = function() {
	if(jQuery('#searchSiteText').val() != 'Search') {
		jQuery('#searchSiteText').css({'color':'#000000'});	
	}
};
SpaceRocket.onSearchFocus = function() {
	if(jQuery('#searchSiteText').val() == 'Search') {
		jQuery('#searchSiteText').val('');
		jQuery('#searchSiteText').css({'color':'#000000'});	
	}
};
SpaceRocket.onSearchBlur = function() {
	if(jQuery('#searchSiteText').val() == '') {
		jQuery('#searchSiteText').val('Search');
		jQuery('#searchSiteText').css({'color':'#dddddd'});
	}
};


// Preloader
SpaceRocket.preload = [];
SpaceRocket.preloadImages = function(value) {
	for(var prop in value) {
		var over = new Image();
		over.src = value[prop];
		SpaceRocket.preload.push(over);
	}
};


// SWF set focus
SpaceRocket.setSWFFocus = function() {
	jQuery('game-swf').focus();
};
	

jQuery(document).ready(SpaceRocket.main);
