$('html').addClass('hidden');



/*
function iPhoneAlert() 
{
	if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i)))
	{
		var question = confirm("Would you like to view the iPhone-optimized version of our site?");
		
		if (question)
		{
			window.location = "http://iphone.rachelgalley.com";
		}
		else
		{
			$.ajax(
			{
				type: "POST",
				url: "http://www.rachelgalley.com/iphone-redirect.php",
				data: "iphone=no"
			});
		}
	}
}

function checkIphoneDeclined()
{
	$.ajax(
	{
		type: "POST",
		url: "http://www.rachelgalley.com/iphone-redirect.php",
		data: "check=1",
		success: function(ret)
		{
			if(ret == false)
			{
				iPhoneAlert();
			}
		}
	});
}
*/

function slideSwitchDesign() 
{
	var active = $('#bc_design_images p:visible');
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#bc_design_images p:first').fadeIn(1500);
	}
}

function slideSwitchInspire() 
{
	var active = $('#bc_inspire_images p:visible');
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#bc_inspire_images p:first').fadeIn(1500);
	}
}


function slideSwitchVert() 
{
	var active = $('#vert_images .vert_image:visible');
	
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#vert_images .vert_image:first').fadeIn(1500);
	}
}

function slideSwitchEnkaiSun() 
{
	var active = $('#enkai_sun_rotate .enkai_sun:visible');
	
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#enkai_sun_rotate .enkai_sun:first').fadeIn(1500);
	}
}

function slideSwitchMystic() 
{
	var active = $('div#mystic_rotate .mystic:visible');
	
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('div#mystic_rotate .mystic:first').fadeIn(1500);
	}
}

function slideSwitch() 
{
	var active = $('#homepage_main .hmain_image:visible');
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#homepage_main .hmain_image:first').fadeIn(1500);
	}
}

function slideSwitchPromo() 
{
	var active = $('#homepage_promo .hpromo_image:visible');
	active.fadeOut(2000);
	
	if(active.next().length)
	{
		active.next().fadeIn(2000);
	}
	else
	{
		$('#homepage_promo .hpromo_image:first').fadeIn(2000);
	}
}

/*
function slideSwitchTwo() 
{
	var active = $('#homepage_promo .hpromo_image:visible');
	active.fadeOut(1500);
	
	if(active.next().length)
	{
		active.next().fadeIn(1500);
	}
	else
	{
		$('#homepage_promo .hpromo_image:first').fadeIn(1500);
	}
}
*/

function share_item(dest, id)
{
	$.ajax(
	{
		type: "POST",
		url: "/share_counter.php",
		data: "site="+dest+"&item_id="+id+"&share=yarp",
		success: function(msg)
		{
		 //console.log( "Data Saved: " + msg );
		}
	});
	
	return false;
}



$(document).ready(function()
{
	//checkIphoneDeclined();
	
	$('.gallery_link').click(function()
	{
		$(this).parent().find('.first_image').trigger('click');
		
		return false;
	});
	
	$('.play_icon').click(function()
	{
		$(this).parent().find('.first_image').trigger('click');
		
		return false;
	});
	
	
	$('#honda_gallery').hover(function()
	{
		var icon = $(this).find('.play_icon');
		
		if(!icon.is(':animated'))
		{
			icon.fadeIn(200);
			$(this).find('.first_image').fadeTo(300, 0.8);
		}
		
	}, function()
	{
		var icon = $(this).find('.play_icon');
		
		if(!icon.is(':animated'))
		{
			icon.fadeOut(200);
			$(this).find('.first_image').fadeTo(300, 1);
		}
	});
	
	$('#honda_video').hover(function()
	{
		var icon = $(this).find('.play_icon');
		
		if(!icon.is(':animated'))
		{
			icon.fadeIn(200);
			$(this).find('.first_image').fadeTo(300, 0.8);
		}
		
	}, function()
	{
		var icon = $(this).find('.play_icon');
		
		if(!icon.is(':animated'))
		{
			icon.fadeOut(200);
			$(this).find('.first_image').fadeTo(300, 1);
		}
	});
	
	
	$('input[name=close]').click(function()
	{
		$('#order_placed').children().fadeOut(function()
		{
			$('#order_placed').slideUp();
		})
	});
	
	/*
	jQuery(function() 
	{
		jQuery(".suggestyyy").suggest("../includes/suggest.php",
		{
			
		});
	});
	*/
	
	$('#trade_nav a').not('#trade_nav .trade_options a').click(function()
	{
		var self = $(this);
		var dd   = $('#trade_options');
		
		if(dd.is(':visible'))
		{
			dd.fadeOut();
		}
		else
		{
			dd.fadeIn();
			$(document).mousemove(function(e)
			{
				if(e.pageX < 800 || e.pageY > 400 || e.pageY < 80)
				{
					dd.fadeOut();
				}
			}); 
		}
		
		return false;
	})
	
	$('.menu1 li').not('.trade_options').not('.last').mouseover(function()
	{
		$('#trade_options').fadeOut();
	});
	
	$('.basket_qty_input').keydown(function(event)
	{
	    if( !(event.keyCode == 8                                // backspace
	        || event.keyCode == 46                              // delete
	        || (event.keyCode >= 35 && event.keyCode <= 40)     // arrow keys/home/end
	        || (event.keyCode >= 48 && event.keyCode <= 57)     // numbers on keyboard
	        || (event.keyCode >= 96 && event.keyCode <= 105))   // number on keypad
	        ) {
	            event.preventDefault();     // Prevent character input
	    }
	});

	
	// Load homepage images
	$('.readmore').delay(2000).fadeIn(1000);
	$('#hpromo_text').delay(1500).fadeIn(1000);
	$('#hpromo_heading').delay(1500).fadeIn(1000);	
	
	if($('div.enkai_sun').length)
	{
		$('div.enkai_sun:first').delay(1100).fadeIn(1000);
		
		$(function() {
			setInterval( "slideSwitchEnkaiSun()", 7800 );
		});
	}
	
	if($('div.vert_image').length)
	{
		$('div.vert_image:first').delay(800).fadeIn(1000);
		
		$(function() {
			setInterval( "slideSwitchVert()", 7000 );
		});
	}
	
	
	if($('div#mystic').length)
	{
		$('div.mystic:first').delay(800).fadeIn(1000);
		
		$(function() {
			setInterval( "slideSwitchMystic()", 7500 );
		});
	}
	
	
	$('.autocomplete_off').attr('autocomplete', 'off');
	
	$('select[name=os4]').change(function()
	{
		var price = $(this).find('option:selected').text().split(' ');
		
		price2 = price[price.length-1].substring(1);
		
		$('input[name=amount]').val(price2);
	});
	
	if($('#bc_design_images').length)
	{
		$('#bc_design_images p:first').delay(700).fadeIn(1000);
		$(function() {
			setInterval( "slideSwitchDesign()", 6000 );
		});
	}
	
	if($('#bc_inspire_images').length)
	{
		$('#bc_inspire_images p:first').delay(1000).fadeIn(1000);
		$(function() {
			setInterval( "slideSwitchInspire()", 6800 );
		});
	}
	
	
	if($('#homepage_promo').length)
	{
		$('#homepage_promo .hpromo_image:first').delay(1000).fadeIn(1000, function()
		{
			
		});
		
		$(function() {
			setInterval( "slideSwitchPromo()", 8000);
		});
	}
	
	(function($){var imgList=[];$.extend({preload:function(imgArr,option){var setting=$.extend({init:function(loaded,total){},loaded:function(img,loaded,total){},loaded_all:function(loaded,total){}},option);var total=imgArr.length;var loaded=0;setting.init(0,total);for(var i in imgArr){imgList.push($("<img />").attr("src",imgArr[i]).load(function(){loaded++;setting.loaded(this,loaded,total);if(loaded==total){setting.loaded_all(loaded,total);}}));}}});})(jQuery);screenshotPreview();$('.expand_press').live('click',function()
{var self=$(this);self.parents('div.press_subcat').css('height','100%');self.removeClass().addClass('contract_press').text('View less');return false;});$('.contract_press').live('click',function()
{var self=$(this);self.parents('div.press_subcat').css('height',370);self.removeClass().addClass('expand_press').text('View All');return false;});$('#collection_items').fadeIn();$('#collections_grid').fadeIn();$('div.more_photos').show();$('#size_image').show();$('input#submit_button').hide();$('div.pouch').show();$('#sort_buttons').show();

	$('#sort_buttons a').click(function()
	{
		var dt = $(this).attr('href').split('-');
		
		if(dt[3]=='col')
		{
			$('#collection_items').fadeOut(100,function()
			{
				$.ajax({
					url:"/includes/price_sort.php",
					type:"POST",
					data:'direction='+dt[1]+'&id='+dt[2]+'&db_name='+dt[0],
					dataType:'html',
					success:function(ret)
					{
						$('#collection_items').html(ret).fadeIn(500);
					}
				});
			});
		}
		else if(dt[3]=='prod')
		{
			$('#collection_items').fadeOut(100,function()
			{
				$.ajax({
					url:"/includes/price_sort.php",
					type:"POST",
					data:'direction='+dt[1]+'&id='+dt[2]+'&prod='+dt[0],
					dataType:'html',
					success:function(ret)
					{
						$('#collection_items').html(ret).fadeIn();
					}
				});
			});
		}
		
		return false;
	});
	
	var tabContainers = $('div.tabs .stockists_table');
	tabContainers.not('#stockists_postcode').hide();
	
	$('div.tabs ul.tabNavigation a').click(function()
	{
		tabContainers.hide().filter(this.hash).show();
		
		return false;
		
	});//.filter(':first').click();


if($('a.zoom1').length)
{
	$("a.zoom1").fancybox(
	{
		'overlayOpacity':0.5,
		'overlayColor':'#000'
	});
	
	$('a.sizes').fancybox(
	{
		'overlayOpacity':0.5,
		'overlayColor':'#000'
	});
}
	$('div.more_photos a').click(function()
{$('a#first').click();return false;});});this.screenshotPreview=function(){xOffset=60;yOffset=80;$("a.screenshot").hover(function(e)
{this.t=this.title;this.title="";var c=(this.t!="")?"<br/>"+this.t:"";$("body").append("<p id='screenshot'><img src='"+this.rel+"' alt='url preview' />"+c+"</p>");$("#screenshot").css("top",(e.pageY-xOffset)+"px").css("left",(e.pageX+yOffset)+"px").css('z-index', 100).fadeIn("fast");},function()
{this.title=this.t;$("#screenshot").remove();});$("a.screenshot").mousemove(function(e){$("#screenshot").css("top",(e.pageY-xOffset)+"px").css("left",(e.pageX+yOffset)+"px");});};function submitForm(str)
{alert(str);document.str.submit();}
function clearForm(){document.searchForm.searchInput.value="";}
function clearSignup(){$('input[name=ea]').val('');}
