$(document).ready(function (){

        // Product Thumb Behaviour
        $('a.product-thumb').hover(function(){
                //$(this).find('span.overlay').css('display', 'block');
                $(this).addClass('product-thumb-hover');
        }, function (){
                //$(this).find('span.overlay').css('display', 'none');
                $(this).removeClass('product-thumb-hover');
        });

        // pre select value for country dropdowns...
	var country = $('select.countries').attr('title');
	$('select.countries option[value='+country+']').attr('selected', 'selected');

        // submit button hover
        $('.submit').hover(function(){
                $(this).css('cursor', 'pointer');
        }, function (){
                $(this).css('cursor', 'auto');
        });

        // Product page images
        $('.product .image img').css('display', 'none');
        $('.product .image img:first').fadeIn(200);
        $('.product .product-thumbs img:first').addClass('active');
        $('.product .product-thumbs img:last').addClass('last');

        $('.product .product-thumbs img').hover(function(){
                $(this).addClass('hover');
                $(this).css('cursor', 'pointer');
        }, function (){
                $(this).removeClass('hover');
                $(this).css('cursor', 'auto');
        });

        $('.product .product-thumbs img').click(function(){
                var tempClass = $(this).attr('alt');
                $('.product .image img').css('display', 'none');
                $('.product .image img.'+tempClass).fadeIn(200);
                $('.product .product-thumbs img').removeClass('active');
                $(this).addClass('active');
        });

        // Empty search input and qty input
        $('input.search-text, input.qty').click(function(){
                $(this).val('');
        });

        // Search results hover
        $('#search input.search-text').attr('autocomplete', 'off');

        $('.search-results').hover(function (){
                
        }, function () {
                $(this).fadeOut(100);
        });

        // Main nav
        $('#main-nav ul li').hover(function () {
                $(this).addClass('hover');
                $(this).find('ul').fadeIn(300);
        }, function (){
                $('#main-nav ul li').clearQueue();
                $(this).removeClass('hover');
                $(this).find('ul').fadeOut(20);
        });
        
        // Feedback Form
        $('#feedback-form input.text, #feedback-form textarea').click(function (){
        	$(this).val('');
        });
        
        $('#feedback-tab .inner .label').hover(function () {
        	$(this).css('cursor', 'pointer');
        }, function () {
        	$(this).css('cursor', '');
        });
        
        $('#feedback-tab .inner .label').click(function (){
        	
        	if ($('#feedback-tab').css('left') === '-258px') {
        		$('#feedback-tab').stop(true,true).animate({left: '0px'}, 150);
        	} else {
        		$('#feedback-tab').stop(true,true).animate({left: '-258px'}, 150);
        	}
        	
        });
        
        $('#feedback-tab a.close').click(function () {
        	$('#feedback-tab').stop(true,true).animate({left: '-258px'}, 150);
        	return false;
        });

		$('form#feedback-form').submit(function (){
			submitFeedback();
			return false;
		});

        // switch order stage one form
        $('#order-stage-1 input#returning').click(function (){

            $('#order-stage-1 .new-customer').slideUp(300);

            if ($('#order-stage-1 .returning-customer').is(':hidden')) {
                $('#order-stage-1 .returning-customer').slideDown(300);
            }
        });

        $('#order-stage-1 input#new').click(function (){

            $('#order-stage-1 .returning-customer').slideUp(300);

            if ($('#order-stage-1 .new-customer').is(':hidden')) {
                $('#order-stage-1 .new-customer').slideDown(300);
            }
        });

        if ($('#order-stage-1 .new-customer p.error').length > 0) {
            $('#order-stage-1 .new-customer').show();
            $('input#new').attr('checked', 'checked');
        }

        if ($('#order-stage-1 .returning-customer p.error').length > 0) {
            $('#order-stage-1 .returning-customer').show();
            $('input#returning').attr('checked', 'checked');
        }
});

function submitFeedback () {
        $.get("/ajax/ajaxfeedback.php", $("#feedback-form").serialize(),
        function(data) {
                if (data != '') {
                        $('form#feedback-form').css('display', 'none');
                        $('#feedback-tab p').html(data);
                        $('#feedback-tab').stop(true,true).delay(500).animate({left: '-258px'}, 150);
                }
        }, "xhtml");
}


