$j=jQuery.noConflict();
 
// Use jQuery via $j(...)
$j(document).ready(function(){

		//$j("#fullsize").append('<div id="spinner"><img src="<?php echo SG2_PLUGIN_URL ?>/images/spinner.gif" alt="slider image" /></div>');
	
			//Set Default State of each portfolio piece
	$j(".paging").show();
	$j(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $j(".window").width();
	var imageSum = $j(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$j(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $jactive.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$j(".paging a").removeClass('active'); //Remove all active class
		$jactive.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$j(".image_reel").animate({ 
			left: -image_reelPosition
		}, 600 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$jactive = $j('.paging a.active').next();
			if ( $jactive.length === 0) { //If paging reaches the end...
				$jactive = $j('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 9000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$j(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$j(".paging a").click(function() {	
		$jactive = $j(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
	
	
	
	
	//menu dropdown dinamico per ie7 e inferiori
	//sfHover = function() {
	var sfEls = document.getElementById("navID").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover"), "");
		}
	}
   
	
	
	

/*$j(".main_view").hover(function () {
    $j("li ul").hide();
  },function () {
	
    

  }
);*/

/*posizione del menu di terzo livello*/

$j(".nav > li > ul > li > a").hover(function(){
			
	
				var pos = $j(this).parent().offset();  
			    var width = $j(this).parent().width();
				var height = $j(this).parent().height();
				//alert(height);
				
				//show the menu directly over the placeholder
			    //$j(".nav li ul").css( { "left": pos.left + "px", "top": (pos.top + height + 1) + "px" } );
				$j(".nav li ul li ul").css( { "margin-top": (-height-6) + "px"} );
			
				
});

/*$j(".nav > li > a").hover(function () {

			$j(".nav > li > ul > li > ul").css({"display":"none"});
    
  },function () {
	
   // $j(this).css({"display":"none"});

  }
);*/


//$j('current_page_item').parent().addClass('current_page_item');

//$j(".nav li ul li:has(ul)").css("background-image":"url(images/bgItemSubMenu.jpg)");

$j(".nav > li:first-child").css({"border-left":"none"});
$j(".nav > li:last-child").css({"border-right":"none"});

$j(".navcentre > ul > li:last-child").children("a").css({"border-right":"none"});

// mettere lo sfondo al li di primo livello se hover ad uno di secondo

$j(".nav > li li a").hover(function () {

			$j(this).parent().parent().parent().children("a").css({"background-image":"url(images/menu_over.jpg)" , "background-repeat":"repeat-x", "background-color":"#00071c" });
			
    
  },function () {
	
   // $j(this).css({"display":"none"});
	$j(this).parent().parent().parent().not(".current_page_item").children("a").css({"background-image":"none" , "background-repeat":"repeat-x", "background-color":"transparent" });

  }
);

// corregge l'hover con sfondo quandi si passa dall'hover di secondo all'hover sul primo

$j(".nav > li > a").hover(function () {

			$j(this).css({"background-image":"url(images/menu_over.jpg)" , "background-repeat":"repeat-x", "background-color":"#00071c" });
			
    
  },function () {
	
   // $j(this).css({"display":"none"});
	$j(this).parent().not(".current_page_item").children("a").css({"background-image":"none" , "background-color":"transparent" });
	//alert("ecco");

  }
);


$j('.boxFornitoriHome').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed:  800,
		timeout: 9000 
	});
	
	
	//togliere outline

	$j("a").each(function() {
		$j(this).attr("hideFocus", "true").css("outline", "none");
	});
	

});
 

