var $j = jQuery.noConflict();


$j(document).ready(function(){
	
    //ifixpng
    //jQuery.ifixpng('/images/pixel.gif');
    $j('.pngfix').ifixpng();



    //lavalamp
	$j(function() {$j('#lavalamp').lavaLamp({fx: 'swing', speed: 333});});
	
	
	
    //search
    $j("#s").blur( function() {
        this.value = (this.value == '')?'Search...':this.value;
        if(this.value == 'Search...' || this.value == '') $j(this).css('color','#ccc');
    });
    $j("#s").focus( function() {
        this.value = (this.value == 'Search...')?'':this.value;
        $j(this).css('color','#20B4E2');
    });
    $j("#search_bar").submit( function(){
        if(!$j("#s").attr("value") || $j("#s").attr("value") == "Search..." ) {
            
            $j.prompt('Il campo <strong>Search</strong> risulta essere vuoto. <br /> Inserisci il testo da ricercare per effettuare una ricerca.');
            return false;
        }
    }); 
    
    
    
    //months
    $j("#months").change( function() {
        //nota: mettere il link nel value
        document.location.href=this.options[this.selectedIndex].value;
    });
    
    
    
    //tree-view
    $j("#browser").treeview();
    
    
    
    //tabs
    $j(function () {
        var tabContainers = $j('div.tabs > div');
    
        $j('div.tabs ul.tabNavigation a').click(function () {
            tabContainers.hide().filter(this.hash).fadeIn();
    
            $j('div.tabs ul.tabNavigation a').removeClass('selected');
            $j(this).addClass('selected');
    
            return false;
        }).filter(':first').click();
    });
    
    

    //back to top
    $j('a.backtotop').click( function() {$j('html,body').animate({scrollTop: 0}, 1500);});
    
    
    
    //comments
    $j("#commentform").submit( function(){
        var errors = "";
        if( $j("#author").length > 0 && !$j("#author").attr("value") ) { errors += "- Nome<br />";  }
        if( $j("#email").length > 0 && !$j("#email").attr("value") ) { errors += "- Email<br />";  }
        if( $j("#comment").length > 0 && !$j("#comment").attr("value") ) { errors += "- Commento<br />";  }
        
        if(errors != "") {
            $j.prompt('I seguenti campi risultano essero incompleti:<br /><br />' + errors + '<br /><br />Correggi i campi incompleti per inserire il commento.');
            return false;
        }
    });
    
    $j('#comments_area ol.commentlist li').hover(
      function() { $j(this).addClass('highlight'); },
      function() { $j(this).removeClass('highlight'); }
    );
    
    
    $j("#author").blur( function() { $j(this).removeClass("focus"); });
    $j("#author").focus( function() { $j(this).addClass("focus"); });
    $j("#email").blur( function() { $j(this).removeClass("focus"); });
    $j("#email").focus( function() { $j(this).addClass("focus"); });
    $j("#comment").blur( function() { $j(this).removeClass("focus"); });
    $j("#comment").focus( function() { $j(this).addClass("focus"); });
    $j("#url").blur( function() { $j(this).removeClass("focus"); });
    $j("#url").focus( function() { $j(this).addClass("focus"); });



    //ie6
    $j('.ie6').click( function(){ $j('#ie6').toggle(); });



    //kwicks 
    $j('.kwicks').kwicks({
	max: 500,
	defaultKwick: 0,
	sticky: true,
	spacing : 0
    });
   


    // Accordion
    $j(".accordion").accordion({
	header: "h4",
	collapsible: true,
	autoHeight: false,
        
	icons: {
	    header: "ui-icon-circle-arrow-e",
   	    headerSelected: "ui-icon-circle-arrow-s"
	}
    });
    
    
    
    //prettyPhoto
    $j("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded'});


});
