$(document).ready(function() {
        
        //var totalMainSlides = $('#slide').children().length;
        var totalSwatchSlides = $('#swatchwrapper').children().length;
        //var currentMain = 2;
        var currentSwatch = 1;
        
        $("#mainHoverLeft").click(function() {
                $('#mainLeft').click();
        });
        
        $("#mainHoverRight").click(function() {
                $('#mainRight').click();
        });
        
        $('#maincontentslider').hover(
                function () {
                        $(".hoverControl").show();
                 }, 
                function () {
                        $(".hoverControl").hide();
                }
        );
        
        $('#mainLeft').click(function(){
                
                
              	$("#slide").not(':animated').animate({marginLeft: "+=1000px"},'slow', 'linear', function() {

	                        var item = $("#slide li:last").clone();
	                        item.prependTo("#slide");
	                        $('#maincontentslider').width( (item.width() * $('#slide').children().length) + 500 );
	                        $("#slide").css("marginLeft", "0px") ;
	                        $("#slide li:last").remove();
	                });
				
                
                
                
        });
        
        $('#mainRight').click(function(){
                
                
                        
                	$("#slide").not(':animated').animate({marginLeft: "-=1000px"},'slow', 'linear', function() {
                           
	                        var item = $("#slide li:first").clone();
	                        item.appendTo("#slide");
	                        $('#maincontentslider').width( (item.width() * $('#slide').children().length) + 500 );
                        
	                        $("#slide").css("marginLeft", "0px") ;
	                        $("#slide li:first").remove();     
	                });
                
                
        });
        
        
        $('#journalLeft').click(function(){
                
                
                $("#swatchwrapper").not(':animated').animate({marginLeft: "+=170px"},'slow', 'linear', function() {
                              
                        var item = $("#swatchwrapper li:last").clone();
                        item.prependTo("#swatchwrapper");
                        $('#journalslider').width( (item.width() * $('#swatchwrapper').children().length) + 100 );
                        $("#swatchwrapper").css("marginLeft", "0px") ;
                        $("#swatchwrapper li:last").remove();
                        
                        
                });
                
                
                $('li .east').tipsy({gravity: 's'});
                
        });
        
        $('#journalRight').click(function(){
                
                
                $("#swatchwrapper").not(':animated').animate({marginLeft: "-=170px"},'slow', 'linear', function() {
                                      
                                var item = $("#swatchwrapper li:first").clone();
                                item.appendTo("#swatchwrapper");
                                $('#journalslider').width( (item.width() * $('#swatchwrapper').children().length) + 100 );
                                $("#swatchwrapper").css("marginLeft", "0px") ;
                                $("#swatchwrapper li:first").remove();
                });
                
                
                $('li .east').tipsy({gravity: 's'});
        });
        
        
        
        $('#a_contact, #b_contact').click(function() {
            
            $('#enquiryform').height($('#footer').offset().top);
            $('#enquiryform').animate({marginTop: "-"+( $('#footer').offset().top - $('#footer').height())},300, 'linear');
            $('#footer').css('overflow-y', 'visible');
            $('#enquiryform').css('position', 'absolute');
            
        });
        
        $('#a_close').click(function() {
            $('#enquiryform').height($('#footer').offset().top);
            $('#enquiryform').animate({marginTop: "+"+( $('#footer').offset().top - $('#footer').height())},800, 'linear', function(){
                $('#footer').css('overflow-y', 'hidden');
                $('#enquiryform').css('position', 'relative');
            });
            
        });
        
    });
