
	

$(function() {

	/*
		if ($("#UserRegisterForm").length > 0) {
		
		
		$('#UserRegisterForm').append($('#UserTermsConditions_')); 
			
		
				$("#UserRegisterForm").validate({
												
					submitHandler: function(form) { 
	
					$.get("https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8", $("#salesForceForm").serialize(), function(data) {
						//alert('Will sumit now');
						form.submit();
					});
				
					},							
						
						
						
												
												
					errorClass: "error-message",							
												
					rules: {
						"data[User][first_name]": {
							required: true,
							minlength: 3
						},
						"data[User][last_name]": {
							required: true,
							minlength: 3
						},
						"data[User][username]": {
							required: true,
							email: true
						},
						"data[User][email_confirmation]": {
							required: true,
							email: true,
							equalTo: "#UserUsername"
						},
						"data[User][password]": {
							required: true
						},
						"data[User][password_confirm]": {
							required: true,
							equalTo: "#UserPassword"

						},
						"data[User][terms_conditions]": {
							required: true

						}

					},
					messages: {
						"data[User][first_name]": "Please enter your first name",
						"data[User][last_name]": "Please enter your last name",
						"data[User][username]": "Your email address must be valid",
						"data[User][email_confirmation]": {
							required: "Please confirm your email address",
							equalTo: "Please enter the same email address as above"
						},
						"data[User][password]": {
							required: "Please provide a password",
							minlength: "Your password must be at least 5 characters long"
						},
						"data[User][password_confirm]": {
							required: "Please confirm your password",
							minlength: "Your password must be at least 5 characters long",
							equalTo: "Please enter the same password as above"
						},
						"data[User][terms_conditions]": "Please read and accept the terms of registration."


					}
				});
				
				
				
				
				newForm = $('<form />')
							.css("display", "none")
							.attr("action", "http://www.emergemedia.co.uk/email.asp")
							.attr("method", "post")
							.attr("id", "salesForceForm");
													
				$('<input />')
					.attr("type", "text")
					.attr("id", "oid")
					.attr("name", "oid")
					.attr("value", "00D20000000K7se")
					.appendTo(newForm);			
				
				$('<input />')
					.attr("type", "text")
					.attr("id", "first_name")
					.attr("name", "first_name")
					.appendTo(newForm);
					
				$('<input />')
					.attr("type", "text")
					.attr("id", "last_name")
					.attr("name", "last_name")
					.appendTo(newForm);
					
				$('<input />')
					.attr("type", "text")
					.attr("id", "email")
					.attr("name", "email")
					.appendTo(newForm);
					
				$('<input />')
					.attr("type", "text")
					.attr("id", "phone")
					.attr("name", "phone")
					.appendTo(newForm);	
					
				$('<textarea />')
					.attr("id", "description")
					.attr("name", "description")
					.appendTo(newForm);	
				
				$('<input />')
					.attr("type", "submit")
					.attr("id", "submit")
					.attr("name", "submit")
					.appendTo(newForm);	
				
				$($("#UserRegisterForm")).before(newForm);
				
				
				
				
				$('#UserFirstName').blur(function() {
						$('#first_name').val($(this).val());						  
				});
				$('#UserLastName').blur(function() {
						$('#last_name').val($(this).val());						  
				});
				$('#UserUsername').blur(function() {
						$('#email').val($(this).val());						  
				});
				$('#UserDataCapture3').blur(function() {
						$('#phone').val($(this).val());						  
				});
				$('#UserDataCapture5').blur(function() {
						$('#description').val($(this).val());						  
				});
				
				

	}
	
	*/
	
	$('.country-selector ul li').addClass('toplevel');
	$('.country-selector ul li ul li').removeClass('toplevel');
	$('.country-selector ul li.toplevel').hover(
	
		function() {
			$(this).addClass('over');
		}, 
		
		function () {
			$(this).removeClass('over');
		}
		
	);
	
	$('body.register .required label').html(function(i, html) {return html + ' <span class="req">*</span>'});

	
	$('h1').css('color', '#c0f');
	
	if ($("body.login_register").length > 0) {
		
		$('#LoginUsername').focus();
		
	}
	


	if ($("input.focus-clear").length > 0) {
		
		$("input.focus-clear").each(function(i) {
		
		$defaulttext = $(this).val();
		
		$(this).val('');
		$(this).css('color', '#333');
		
				$(this).focus(function() {
					//$defaulttext = $(this).val();
					if ($(this).val() == $defaulttext) {
						$(this).val('');
					}
				}).blur(function() {
					if ($(this).val() == '') {
						//$(this).val($defaulttext);
					}
				}).keypress(function() {
					$(this).removeClass("focus-clear");
				});
		});
		
	}


	if ($(".single-product").length > 0) {
		
		prodh1 = $(".single-product h1").html();
		prodprice = $(".single-product p.price");
		prodprice.css("display", "none");
		
		$(".single-product h1").html(prodh1 + " " + prodprice.text().replace('RRP ','RRP&nbsp;'));
		$(".single-product h1").html($(".single-product h1").text().replace('(ref: ','(ref:&nbsp;'));
		
	}

	
	Cufon.replace('h2');
	
	$('.the-used-kitchen-company h1').css("display", "none");
	$('.the-used-kitchen-company .eight p').eq(0).addClass("highlight");
	
	$('p.highlight').each(function(){
    	var me = $(this);
    	me.html( me.text().replace(/(^\w+)/,'<strong>$1</strong>') );
  	});
	
	$("p.highlight strong").each(function() {
      var text = $(this).html();
      $(this).html(text.replace(/^([A-Za-z0-9])/g,'<span>$1</span>'));
   });

	Cufon.replace('h1', { fontFamily: 'Interstate-Light', fontWeight: '400' })
	Cufon.replace('span.country', { fontFamily: 'Interstate-Light', fontWeight: '400' })
	Cufon.replace('.single-product h1', { fontFamily: 'Interstate LightItalic', fontWeight: '300' });
	
	
	
	
	if ($(".gallery_demo_unstyled").length > 0) {

			$('.gallery_demo_unstyled').addClass('gallery_demo').addClass('clear');			
			
			$('ul.gallery_demo li').each(function(idx) {
				$(this).data('index', (++idx));
			});
		
		   var car = $('ul.gallery_demo').jcarousel({
				scroll: 5,
				initCallback: initCallbackFunction
			})
	
				
			$('ul.gallery_demo li:first').addClass('active');
			
		   // window.setInterval(function(){
			//    $.galleria.next()
			//}, 3000) // must be set in miliseconds
		 
			// $('#slideshow').fadeIn();
				
			$('ul.gallery_demo').galleria({
										  
									  
											
					history   : false, // activates the history object for bookmarking, back-button etc.
					//insert: '#img',
					
					onImage: function(image, caption, thumb) {   
					
					// fade in the image 
				    image.hide().fadeIn(1000);
					
					// animate active thumbnail's opacity to 1, other list elements to 0.6
					thumb.parent().fadeTo(0, 1000).siblings().fadeTo(0, 1000);
					
		
					$('#img')
						.trigger('image-loaded');
									
					},
					
					onThumb : function(thumb) { // thumbnail effects goes here
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// if thumbnail is active, fade all the way.
						var _fadeTo = _li.is('.active') ? '1' : '1';
						
						// fade in the thumbnail when finnished loading
						thumb.css({display:'none', opacity:_fadeTo}).fadeIn(0);
						
						// hover effects
						thumb.hover(
							function() { thumb.fadeTo('fast',1); } // don't fade out if the parent is active
						)
					}
				});
			
			}
			
			
			
		function initCallbackFunction(carousel) {
				$('#img').bind('image-loaded',function() {
					var idx =  $('ul.gallery_demo li.active').data('index') - 2;
			   //     alert('j');
					carousel.scroll(idx);
					return false;
				});
			};
	
	
	});
