

$.fn.image = function(src,f){

  return this.each(function(){

  var i = new Image();

  i.onload = f;

  i.src = src;

  }); 

}



function scrollShow() {

$('.shownav').scrollable( {

size: 5,

horizontal:true, 

speed: 300,

prev:'.prev',

next:'.next',

activeClass:'active',

items: 'ol'

});

}



function navShow() {

$('#projecto .shownav li a').click(function(){

var ahref = $(this).attr('href');

var atitle = $(this).children().attr('alt');

var imgsrc = $(this).children().attr('src').replace('45x30','400x250');

var imgalt = $(this).children().attr('title');



if($('#projecto .show img').attr('src') != imgsrc) {

  $('#projecto .show img').attr({src:'/wp-content/themes/mcjdj/imagens/imgloader.gif'}).addClass('loading');

  

  var to = setTimeout(function(){

    $('#projecto .show a').attr({href:ahref,title:atitle});	

    $('#projecto .show img').attr({src:imgsrc,alt:imgalt}).removeClass('loading');  

  },3000);

  

  $("#projecto .show a").image(imgsrc,function(){

    $('#projecto .show a').attr({href:ahref,title:atitle});	

    $('#projecto .show img').attr({src:imgsrc,alt:imgalt}).removeClass('loading');

    clearTimeout(to);

  });

}

else {

return false;

}

});  

}



function fancyShow() {

$('div.show a').fancybox({

'hideOnContentClick': true,

'overlayShow': true,

'overlayOpacity': 0.75

});

}



function funcShow() {	

scrollShow();

navShow();

fancyShow();

}



function scrollAnchors() {

function filterPath(string) {

return string

.replace(/^\//,'')

.replace(/(index|default).[a-zA-Z]{3,4}$/,'')

.replace(/\/$/,'');

}

var locationPath = filterPath(location.pathname);

$('a[href*=#]').each(function() {

var thisPath = filterPath(this.pathname) || locationPath;

if (locationPath == thisPath

&& (location.hostname == this.hostname || !this.hostname)

&& this.hash.replace(/#/,'') ) {

var $target = $(this.hash), target = this.hash;      

if (target && target != '#prev' && target != '#next') {

var targetOffset = $target.offset().top;

$(this).click(function(event) {

event.preventDefault();

$('html, body').animate({scrollTop: targetOffset}, 1000, function() {

location.hash = target;

});

});

}

}

});

}





$(document).ready(function() {



if( jQuery.browser.msie && (jQuery.browser.version < 7) ) {

	// IE6

}

else if(location.pathname == '/'){

	scrollAnchors();

	$('#nav a[href=#home]').click().addClass('active');

}



// safari

if(jQuery.browser.safari){

$('html').addClass('safari');

}



// Funcoes nav

$('#nav a').click(function() {



if($(this).attr('href') == location.hash) { return false; }



var href = $(this).attr('href').replace('#','');

$('#nav a.active').removeClass('active');

$(this).addClass('active');



if( href == 'about' ) {

$('ul.nav-b').attr( { className: 'nav-a' });

$('div.foot-b').attr( { className: 'foot-a' });

}



else if( href == 'home' ) {

$('ul.nav-b').attr( { className: 'nav-a' });

$('div.foot-a').attr( { className: 'foot-b' });

}



else {

$('ul.nav-a').attr( { className: 'nav-b' });

$('div.foot-a').attr( { className: 'foot-b' });

}



});



// Seleccionar Projecto

$('#selector').scrollable({

size: 3,

horizontal:true,

prev:'.prev',

next:'.next',

activeClass:'active',

items: 'ul'

});



$('#selector li a').click(function(){

var href = $(this).attr('href');

$('#projecto').html('<div class="loading"></div>');

$.get( href, { js:'' }, function(data){

$('#projecto').html(data);

funcShow();

});

});



funcShow();



});