	$(function(){			   
		//addtofavs($("#add-to-favs"), 'http://www.superstores.co.uk', 'co-op superstores'); //add to favourites
		//topnav($('#top-nav')); // top navigation 		
		
		
		$('#banner .body') 
			.after('<div id="banner-pagination">') 
			.cycle({ 
				fx:     'fade', 
				speed:  'slow', 
				timeout: 5000, 
				pager:  '#banner-pagination' 
		}); // banner			
		
		
		
		/* Add to Favourites */
		
		
		/* Carousel */
		
		productScroll($('#carousel-recommends'), 960, 0);
		productScroll($('#carousel-clearance'),  960, 5000);
		productScrollMini($('#carousel-just-in'));
		
		closeitems($('#recently-viewed .item'));
		
		gallery();
		
		
		var $my_tabs = $('#product-tabs').tabs();
                $('#rate_this_product').click(function() { // bind click event to link
                    $my_tabs.tabs('select', 1); // switch to second tab
                });
		
		leftnav($('#left-nav'));
	
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		$("#top-nav ul:first > li").bind('touchstart', function(){ //touchend, touchstart
			$("#top-nav ul li.hover").each(function(){
				$(this).removeClass('hover');
				$(this).find('ul:first').hide();					
			});		
			$(this).addClass('hover');
			$(this).find('ul:first').show();			
		});
		
		/*
		$("#top-nav ul:first > li ul li a").bind('touchstart', function(){
			$("#top-nav ul li.hover").each(function(){
				$(this).removeClass('hover');
				$(this).find('ul:first').hide();	
			});	
		});
		*/
		
	} else {	
	
		$("#top-nav ul:first > li").hover(
			function () {
				$(this).addClass('hover');
				$(this).find('ul:first').show();
			},
			function () {
				$(this).removeClass('hover');				
				$(this).find('ul:first').hide();
			}
		);
		
		$("#top-nav ul:first > li ul li .sub-title, #top-nav ul:first > li ul li .title").hover(
		
		
		
			function () {
				topLevelClass = $(this).parent().parent().parent().parent();
				
				$(this).addClass('hovered');
			
				
				if(topLevelClass.hasClass('by-department')) {
					
					if($(this).hasClass('title')) {
						$(this).removeClass('hovered');
					}					
				} 
				
				
				
				
			},
			function () {
				$(this).removeClass('hovered');				
			}
		);		
	}
		// input value replacement 
		
		$('#search-box .textbox, #subscribe-box .textbox').each(function() {
			var default_value = this.value;
			$(this).focus(function() {
				if(this.value == default_value) {
					this.value = '';
				}
			});
			$(this).blur(function() {
				if(this.value == '') {
					this.value = default_value;
				}
			});
		});
                
                // Handles the Auto-complete functionality for product search
                $("#ajax-product-search").autocomplete("cart.php", {
                    width: 400,
                    scroll: false,
                    selectFirst: false,
                    extraParams: {'m' : 'quick_search'},
                    max: 10,
                    onResults : function(row_count) {
                        if (row_count >= 10) {
                            $('.ac_results').find('ul').append('<li class="no-action" style="text-align: right;"><a href="/cart.php?m=search_results&search=' + $("#ajax-product-search").val() + '&product-search=">View All &gt;</a></li>');
                        }
                    }
                });

                $("#ajax-product-search").result(function() {
                    // From value is in field, trigger form submit?
                    $(this).parent().submit();
                });
		
		$("#checkout").click(function(){
		    checkout();
		});
        
		/* Tweet box */
		

		twttr.anywhere(function (T) {

        T("#tbox").tweetBox({

          height: 100,

          width: 400,

          defaultContent: "@MillysStore",
		  
		  label: "Tweet us!"

        });

      });
	
	})

