/*-----------------------------------------------------------------------------
Common JS

date:      06/06/2011
author:    [Olivier Robert]
-----------------------------------------------------------------------------*/

$(function(){

	/* Initialise */
	
	var Init = (function() {
	
		var f = {};
		
		detect_webkit = (function() {
		
			if ($.browser.webkit) {
			
				$('body').addClass('is_webkit');
			}
			
		})();
		
		var heroImage = (function(){
		
			$('#hero_image').makeSlider({
				speed: 5000,
				parentEl: 'div',
				childrenEl: 'dl',
				disableSlideClick: true,
				debug: false
			});
			
		})();
		
		return f;
	
	})();
		
	/* CONTACT Form */	
	
	var contactForm = (function(){
                    
    	$('select[name=enquiryType]').css('display','none');
    	
    	create_select();
    	
    	function create_select() {
    
        	$new_select = '<select id="guava_enquiry_categories">';
        
        	$('select[name=enquiryType] option').each(function(){
        	
        		var $this = $(this),
        			$text = $this.text();
        		
        		switch($text) {
        		
        			case 'info@guavauk.com':
        			
        				$new_select += '<option value="General Enquiries">General Enquiries</option>';
        			
        			break;
        			
        			case 'dealer@guavauk.com':
        			
        				$new_select += '<option value="International Dealer Enquiries">International Dealer Enquiries</option>';
        			
        			break;
        			
        			case 'parts@guavauk.com':
        			
        				$new_select += '<option value="International Spare Parts">International Spare Parts</option>';
        			
        			break;
        			
        			case 'aid@guavauk.com':
        			
        				$new_select += '<option value="Aid & Development">Aid & Development</option>';
        			
        			break;
        			
        			case 'service@guavauk.com':
        			
        				$new_select += '<option value="Guava Guildford Service Centre">Guava Guildford Service Centre</option>';
        			
        			break;
        		
        		}
        	
        	});
        	
        	$new_select += '</select>';
        	
        	$('span.enquiryType').append($new_select);
        	
        	$('select#guava_enquiry_categories').live('change', function(){
        	
        		var $this = $(this),
        			$value = $(this).val(),
        			$enquiryType = $('select[name=enquiryType]');
        		
        		switch($value) {
        		
        			case 'General Enquiries':
        			
        				$enquiryType.val('info@guavauk.com');
        			
        			break;
        			
        			case 'International Dealer Enquiries':
        				
        				$enquiryType.val('dealer@guavauk.com');
        			
        			break;
        			
        			case 'International Spare Parts':
        			
        				$enquiryType.val('parts@guavauk.com');
        			
        			break;
        			
        			case 'Aid & Development':
        			
        				$enquiryType.val('aid@guavauk.com');
        			
        			break;
        			
        			case 'Guava Guildford Service Centre':
        			
        				$enquiryType.val('service@guavauk.com');
        			
        			break;
        		
        		}
        	});
    	}
                        
    })();	

	/* LOADER */
	
	var Loader = (function(){
	
		if ($('body').hasClass('home')){
		
			var thumbFeatureHover = (function(){
			
				var $thumbFeature   = $('section.thumb_feature'),
					$thumbItems     = $thumbFeature.find('li'),
					$thumbItemsText = $thumbItems.children('p');
					
				var defaultHeight = 120;
					
				var Init = (function(){
				
					$thumbItemsText.css({display:'none', visibility:'hidden'});
							
				})();						
					
				////////////////////////
				//
				// 		EVENTS
				//
				///////////////////////
			
				$thumbItems.hover(function(){
				
					var $this      = $(this),
						elHeight   = $this.height(),
						$text      = $this.children('p'),
						textHeight = $text.height();
						
					var padding = 10,
						newHeight = elHeight + textHeight + padding;
						
					$this.stop().animate({height: newHeight + 'px'}, 300, function(){
					
						$(this).children('p')
						.css({display:'block', visibility:'visible'})
						.fadeTo(200, 1);
					
					});
				
				
				}, function(){
				
					var $this = $(this),
						$text = $this.children('p');
					
					$(this).children('p')
					.fadeTo(100, 0)
					.css({display:'none', visibility:'hidden'});
					
					$this.stop().animate({height: defaultHeight + 'px'}, 100);
					
				});
				
				$thumbItems.click(function(e){
					
					e.preventDefault();
					
					var link = $(this).find('a').attr('href');
					
					window.location.href = link;
					
					return false;
				
				});
			
			})();
				
		}
	
	})();
		
});
