/* carte regalo new hp - ocotober 2011 */

var last_vendor_opened;

var opened = false;

function elements() {
	
	$('<p><a href="#" class="close-vendor-details">x</a></p>').appendTo("div.vendor-card");
	
}

function hide_vendors_details() {

	$( "div.vendor-details").hide();

}

function slideup_vendors_details() {

	$( "div.vendor-details").slideUp( 400 , "swing" );

}

function logos_hover( element ) {
			
	current_vendor_opened = "div#" + element.id + "-details";
	
	if( current_vendor_opened != last_vendor_opened ) {
		
		hide_vendors_details();
		
		last_vendor_opened = "div#" + element.id + "-details";
		
		if( opened == false ) {
		
			$(last_vendor_opened).slideDown( 400 , "swing" );
			
			opened = true;
			
		}
		else 
		{
			
			$(last_vendor_opened).fadeIn();
			
		}
		
	}
	else {
	
		slideup_vendors_details();
	
		last_vendor_opened = "";
		
		opened = false;
	
	}

}

function manage_vendors_details() {

	$( "div#logos a" ).hoverIntent(

		function() {
			
			logos_hover( this )
		
		},
		
		function() {
		
			// do nothing
		
		}
		
	);	
	
	$( "div#logos a" ).click(

		function( e ) {
			
			e.preventDefault();
			
		}
		
	)
	
	$( "a.close-vendor-details" ).click(
										
		function( e ) {
		
			slideup_vendors_details();
			
			last_vendor_opened = "";
				
			opened = false;
		
			e.preventDefault();
		
		}
		
	);	

}

function manage_logos() {
	
	jQuery('#mycarousel').jcarousel(
		
		{
									
		auto: 5,
		wrap: 'last',
		visible: 5,
		scroll: 5,
		initCallback: mycarousel_initCallback,
		buttonNextHTML: null,
        buttonPrevHTML: null
       
		}
		
	);							  
	
}

function mycarousel_initCallback(carousel) {

	// Pause autoscrolling if the user moves with the cursor over the clip.
    
	carousel.clip.hover(function() {
    
		carousel.stopAuto();
    
	}, function() {
    
		carousel.startAuto();
    
	});
	
	$("p#mycarousel-next a").bind('click', function() {
		
		carousel.startAuto(0); // Disable autoscrolling if the user clicks the prev or next button. 
		
        carousel.next();
		
        return false;
    
	});

    $("p#mycarousel-prev a").bind('click', function() {
    
		carousel.startAuto(0); // Disable autoscrolling if the user clicks the prev or next button.
	
		carousel.prev();
        
		return false;
    
	});
	
};

function manage_slides() {

	$( "#slides-container" ).tabs( 
	
		{ 
		
		event: "click", 
		
		fx: {
		
			opacity: "toggle",
			duration: "slow"
		
		},
		
		spinner: "loading...",
		cache: true
		
		}
		
	).tabs( "rotate" , 7000 , false )

}

$( document ).ready(

	function() {
		
		hide_vendors_details();
		
		elements();
		
		manage_vendors_details();
		
		manage_logos();
		
		manage_slides();
		
	}
	
);
