//COMMON TO ALL PAGES//


//ITA ToolTIP
$(function(){ 
$("a#ita").hover(function(){
$("#prossima").stop(true,true).fadeIn("slow");
},function(){
$("#prossima").stop(true,true).fadeOut("slow");
return false;
});
});

//JUST FOR HOMEPAGE-Featured projects-//
$(function(){
$("#featured ul li").hover(function(){
$(this).children(".hover").stop(true,true).fadeOut(450);
},function(){
$(this).children(".hover").stop(true,true).fadeIn(450);
return false;
});

    // homepage connect behavior
    $('#home-connect').hover(
    function(){
       $(this).find('span.msg')
              .animate({
                'opacity' : 0.4
              })
              .siblings('span')
              .fadeIn();
    },
    function(){
       $(this).find('span.msg')
              .animate({
                'opacity' : 1
              })
              .siblings('span')
              .fadeOut();
    });
    // disable click behavior on the only link in the div
    // if javascript is disabled users can still navigate
    // to the contact page
    $('#home-connect a.control').click(function(evt){
       evt.preventDefault();
    });

    // bind hover and lick actions to the view profile link
    // on the homepage
    $('#intro a.studio-profile').hover(
    function(){
       $(this).next()
              .fadeIn();
    },
    function(){
       $(this).next()
              .fadeOut();
    }).click(function(evt){
      evt.preventDefault();
    }).click(function(evt){
      evt.preventDefault();
       $(this).next()
              .hide();
    });

    $('#featured p.all a').hover(
    function(){
       $(this).next()
              .fadeIn();
    },
    function(){
       $(this).next()
              .fadeOut();
    });

    // make tabs boxes of equal height
    var maxHeight = 0;
    var $homeTabs = $('#home-tabs > div');
    $homeTabs.each(function(){
      if(maxHeight < $(this).height()){
        maxHeight = $(this).height()
      }else{
        // the height is at it's heighest
        // do nothing
      }
    });
    $('#profile, #our-name').height(maxHeight);
});


//JUST FOR WORK PAGE-work&work-filter//
$(function(){
$("#work ul li").hover(function(){
$(this).children(".hover").stop(true,true).fadeOut(450);
},function(){
$(this).children(".hover").stop(true,true).fadeIn(450);
return false;
});
});
	
	
//JUST FOR PROFILE PAGE//
$(function(){
$("#elemental").hide(0);
$("p.about a").click(function(evt){
  evt.preventDefault();
$("#elemental").stop(true,true).fadeIn("slow");
});

$("a.close, p.back a").click(function(evt){
  evt.preventDefault();
$("#elemental").stop(true,true).fadeOut("slow");
});
});

function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

function play_vimeo(elm, indx){
var vimeosrc = $('#embed-'+indx).children().attr('src');
if (strpos(vimeosrc,'?')) vimeosrc  += '&autoplay=true'; else vimeosrc +='?autoplay=true';
$(elm).parent().hide();
$('#embed-'+indx).children().attr('src',vimeosrc);
$('#embed-'+indx).show();
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function stopiframes(){
    $('.items iframe').each(function(index) {
        var isrc = $(this).attr('src');
        var new_src = str_replace('&autoplay=true', '', isrc);
        new_src = str_replace('?autoplay=true', '', new_src);
        $(this).parent().prev().show();
        $(this).parent().hide();
        $(this).attr('src',new_src );
    });
}
