// JavaScript Document

/* Mobile version
  if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
    {}

  if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
  document.location = "mobile/";
}
*/

// Google web fonts directory 
WebFontConfig = {
  google: { families: [ 'Droid+Sans:400,700:latin', 'Droid+Serif:400,400italic,700,700italic:latin' ] }
  };
(function() {
  var wf = document.createElement('script');
  wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
  wf.type = 'text/javascript';
  wf.async = 'true';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(wf, s);
})();
  
// Inizializzazione
$(document).ready(function() {

  // IE Bumper
  if( $.browser.msie && ( $.browser.version < "9.0" ) )
    {
     $.fn.colorbox({href:'info.html', open:true, iframe:true, width:"640px", height:"380px"});
    } 
  
  // Webkit text size adjust
  $("body").css("-webkit-text-size-adjust", "95%");
  
  // External Links
  $("a[rel='external'], a[class='pdf']").attr('target', '_blank');
    
  // Twitter like tips
	$('a[title], #test input[title], #test button[title], #mailto input[title], #mailto textarea[title], #mailto button[title]').poshytip({
		className: 'tip-twitter',
		//showTimeout: 1,
		//showOn: 'none',
		alignTo: 'target',
		alignX: 'center',
		offsetY: 10, // 5
		allowTipHover: false,
		fade: true, // false
		//slide: false
	});
	
	$('#search input, #search button').poshytip({
		className: 'tip-twitter',
		//showTimeout: 1,
		alignTo: 'target',
		alignX: 'center',
		offsetY: 20, // 5
		allowTipHover: false,
		fade: true, // false
		//slide: false
	});
	
	// Nivo Slider
	$('#portfolio li[id]').nivoSlider({ 
		effect:'random', 							            //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, 								            //Set starting Slide (0 index)
		directionNav:false, 						          //Next & Prev (true)
		directionNavHide:true, 					        	//Only show on hover 
		controlNav:false, 							          //1,2,3... (true)
		controlNavThumbs:false, 					        //Use thumbnails for Control Nav
    controlNavThumbsFromRel:false, 				    //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', 			    //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', 		//...this in thumb Image src
		keyboardNav:true, 							          //Use left & right arrows
		pauseOnHover:true, 							          //Stop animation while hovering
		manualAdvance:false, 						          //Force manual transitions
		captionOpacity:0.75, 						          //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} 				    	//Triggers after all slides have been shown
	});
	
	// Placeholder fix
  $('[placeholder]').focus(function() {
  var input = $(this);
  if (input.val() == input.attr('placeholder')) {
    input.val('');
    input.removeClass('placeholder');
    }
  }).blur(function() {
  var input = $(this);
  if (input.val() == '' || input.val() == input.attr('placeholder')) {
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
  }
  }).blur();

	// Slide-down images
	$('.cover').hover(function(){
		$(this).find('img').animate({top:'30px'},{queue:false,duration:300});
	}, function(){
		$(this).find('img').animate({top:'0px'},{queue:false,duration:300});
	});
	
	// Slide to top
  $("li[id='top'] a").click(function() {
    $("html, body").animate({ scrollTop : 0 }, "slow");
        return false;
    });
 
  // Colorbox - http://colorpowered.com/colorbox/
  $("a[class='colorbox']").colorbox();
  $("li[id='info'] a").colorbox({width:"640px", height:"380px", iframe: true, title:"Informazioni e note tecniche di utilizzo del sito"});
  
  // Treeview - http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
  $("#webstandards, #newstandards, #selection, #download, #history, #infoline").treeview({animated: "fast", /*persist: "location",*/ collapsed: true, unique: true});
  
  // Snippet - http://www.steamdev.com/snippet/
  $("pre.htmlCode").snippet("html",{style:"ide-msvcpp", clipboard:"../js/ZeroClipboard.swf"});
  $("pre.cssCode").snippet("css",{style:"ide-msvcpp", clipboard:"../js/ZeroClipboard.swf"});
  $("pre.jsCode").snippet("javascript",{style:"ide-msvcpp", clipboard:"../js/ZeroClipboard.swf"});
  $("pre.phpCode").snippet("php",{style:"ide-msvcpp", clipboard:"../js/ZeroClipboard.swf"});
  	
});
