jQuery(document).ready(function($) {	
		
	//Execute the homepage slideShow, set 4 seconds for each images
	//simpleSlide({
	//	'set_speed': 500 				// Integer. Sets speed of all animations. Represented in milliseconds.
	//});


// Add this javascript, and ensure it appears after the simpleSlide() call

	//$('.auto-slider').each( function() {
	  //  var related_group = $(this).attr('rel');
	
	    //window.setInterval("simpleSlideAction('.right-button', " + related_group + ");", 4000);
	//});
	
    function formatText(index, panel) {
		  return index + "";
	  };
    	  
    $(function () {
    
        $('.anythingSlider').anythingSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 5000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 600,             // How long the slide transition takes
            hashTags: false,                 // Should links change the hashtag in the URL?
            buildNavigation: true
            /*buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "Go",                // Start text
		        stopText: "Stop",               // Stop text
		        navigationFormatter: formatText // Details at the top of the file on this use (advanced use)*/
        });
        
        $("#slide-jump").click(function(){
            $('.anythingSlider').anythingSlider(6);
        });
        
    });
	
	

	$("#tabs").tabs();

	$(".bikesbox").jCarouselLite({
	      btnNext: ".next",
	      btnPrev: ".prev",
	      visible: 3
	});
	
	
	$("ul.bikespics li img").click(function () { 
	
		var imageurl = $(this).attr("src");
		$("#mainBikePhoto").attr("src",imageurl);
			
	});
	
	$("#mainBikePhoto").addClass('rounded');
	
	$(".bikespicbox").jCarouselLite({
	      btnNext: ".next",
	      btnPrev: ".prev",
	      visible: 3,
	      circular: false
	});
	
	$("a[rel='bikegallery']").colorbox();
	$("a.colorbox").colorbox({iframe: true, transition:'fade', speed:500, innerWidth:"340px", innerHeight:"255px",scrolling: false});
	$("img.rounded").load( function () {
		var img = $(this);
	 
		// build wrapper
		var wrapper = $('<div class="rounded_wrapper"></div>');
		wrapper.width(img.width());
		wrapper.height(img.height());
	 
		// move CSS properties from img to wrapper
		wrapper.css('float', img.css('float'));
		img.css('float', 'none')
	 
		wrapper.css('margin-right', img.css('margin-right'));
		img.css('margin-right', '0')
	 
		wrapper.css('margin-left', img.css('margin-left'));
		img.css('margin-left', '0')
	 
		wrapper.css('margin-bottom', img.css('margin-bottom'));
		img.css('margin-bottom', '0')
	 
		wrapper.css('margin-top', img.css('margin-top'));
		img.css('margin-top', '0')
	 
		wrapper.css('display', 'block');
		img.css('display', 'block')
	 
		// wrap image
		img.wrap(wrapper);
	 
		// add rounded corners
		img.after('<div class="tl"></div>');
		img.after('<div class="tr"></div>');
		img.after('<div class="bl"></div>');
		img.after('<div class="br"></div>');
		
		
	});


	var g_items_per_page = 10;
	var g_filter = 'all';
	var g_sort = 'year';

	function pageselectCallback(page_index, jq){
	    var items_per_page = g_items_per_page;
	    var offset = page_index * items_per_page;
	    var new_content = jQuery('#hiddenresult div.result').slice(offset, offset + items_per_page).clone();
	    jQuery('#searchresult').empty().append(new_content);
	    return false;
	}
	
	
	function initPagination() {
	  var num_entries = jQuery('#hiddenresult div.result').length;
	  
	  $("#totalBikes").html(num_entries);
	
	  // Create pagination element
	  var pagination_options = {
	    num_edge_entries: 2,
	    num_display_entries: 8,
	    callback: pageselectCallback,
	    items_per_page: g_items_per_page
	  }
	
	  jQuery("#pagination").pagination(num_entries, pagination_options);
	  
	  jQuery("#pagination").show();
	  
	}

	var siteUrl = window.location.pathname;
	
	var urlArray = siteUrl.split('/');
	
	var lastItem = urlArray.length;
		
	if(urlArray[lastItem-2]=='touring'){
		var bikeFamily = 'touring';
	}

	if(urlArray[lastItem-2]=='dyna'){
		var bikeFamily = 'dyna';
	}

	if(urlArray[lastItem-2]=='softail'){
		var bikeFamily = 'softtail';
	}

	if(urlArray[lastItem-2]=='sportster'){
		var bikeFamily = 'sportster';
	}

	if(urlArray[lastItem-2]=='vrsc'){
		var bikeFamily = 'vrsc';
	}

	if(urlArray[lastItem-2]=='cvo'){
		var bikeFamily = 'cvo';
	}

	if(urlArray[lastItem-2]=='trike'){
		var bikeFamily = 'trike';
	}

	if (bikeFamily) {} else { var bikeFamily = ''; }
	
	var g_filter='all';
	var y_filter='all';
	var b_filter='all';
	var c_filter='all';

	if ($.cookie("bikeFamily") == bikeFamily && ($.cookie("g_filter") != "all" || $.cookie("y_filter") != "all" || $.cookie("b_filter") != "all" || $.cookie("c_filter") != "all" || $.cookie("g_sort") != 'year')) {
	
	    $('#newusedBikes').val($.cookie("g_filter"));
	    $('#filterYear').val($.cookie("y_filter"));
	    $('#filterBrand').val($.cookie("b_filter"));
	    $('#filterColor').val($.cookie("c_filter"));
		var g_filter=$.cookie("g_filter");
		var y_filter=$.cookie("y_filter");
		var b_filter=$.cookie("b_filter");
		var c_filter=$.cookie("c_filter");
		
		$(".sortby a").removeClass('current');
		
		if ( $.cookie("g_sort") == "year" ) { $("#sortYear").addClass('current'); $("#sortYear").attr("disabled", "true"); }
		if ( $.cookie("g_sort") == "model" ) { $("#sortModel").addClass('current'); $("#sortModel").attr("disabled", "true"); }
		if ( $.cookie("g_sort") == "nameZA" ) { $("#sortZA").addClass('current'); $("#sortZA").attr("disabled", "true"); }
		if ( $.cookie("g_sort") == "nameAZ" ) { $("#sortAZ").addClass('current'); $("#sortAZ").attr("disabled", "true"); }

	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   		
	} else {

	    $.cookie("g_filter", null);
	    $.cookie("y_filter", null);
	    $.cookie("b_filter", null);
	    $.cookie("c_filter", null);
	    $.cookie("g_sort", null);
   	    //$.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	}





	// inventory view stuff
	
	$("#filterAll").click(function () { 
	
		$("#searchresult").html('Loading...');
		$(".viewby a").removeClass('current');
		$(this).addClass('current');
		$(this).attr("disabled", "true");
		
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	});
	
	$('#newusedBikes').change(function(){
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
		$("#searchresult").html('Loading...');
		$("#pagination").hide();		
	    jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);	    
	});	

	$('#filterYear').change(function(){
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
		$("#searchresult").html('Loading...');
		$("#pagination").hide();		
	    jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);	    
	});	

	$('#filterBrand').change(function(){
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
		$("#searchresult").html('Loading...');
		$("#pagination").hide();		
	    jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);	    
	});	
	
	$('#filterColor').change(function(){
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
		$("#searchresult").html('Loading...');
		$("#pagination").hide();		
	    jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);	    
	});	
	
	$("#sortYear").click(function () { 
	
		$("#searchresult").html('Loading...');
		$(".sortby a").removeClass('current');
		$(this).addClass('current');
		$(this).attr("disabled", "true");
		
		var g_sort='year';
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_filter", g_filter, { path: '/' });
	    $.cookie("y_filter", y_filter, { path: '/' });
	    $.cookie("b_filter", b_filter, { path: '/' });
	    $.cookie("c_filter", c_filter, { path: '/' });
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	});
		
	$("#sortModel").click(function () { 
	
		$("#searchresult").html('Loading...');
		$(".sortby a").removeClass('current');
		$(this).addClass('current');
		$(this).attr("disabled", "true");
		
		var g_sort='model';
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	});
		
	$("#sortAZ").click(function () { 
	
		$("#searchresult").html('Loading...');
		$(".sortby a").removeClass('current');
		$(this).addClass('current');
		$(this).attr("disabled", "true");
		
		var g_sort='nameAZ';
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	});
	
	$("#sortZA").click(function () { 
	
		$("#searchresult").html('Loading...');
		$(".sortby a").removeClass('current');
		$(this).addClass('current');
		$(this).attr("disabled", "true");
		
		var g_sort='nameZA';
	    var g_filter = $('#newusedBikes :selected').val();
	    var y_filter = $('#filterYear :selected').val();
	    var b_filter = $('#filterBrand :selected').val();
	    var c_filter = $('#filterColor :selected').val();
	    $.cookie("g_sort", g_sort, { path: '/' });
   	    $.cookie("bikeFamily", bikeFamily, { path: '/' });
	
	   	jQuery('#hiddenresult').load('/wp-content/themes/harley/snippet.php?family='+bikeFamily+'&filter='+g_filter+'&color='+c_filter+'&brand='+b_filter+'&year='+y_filter+'&sort='+g_sort, null, initPagination);
	   	
	});	
	
//	Cookie

	
});


