$(document).ready(function() {


//===========START fix for scroll=======//
var withinElement = function(event) {
  // Check if mouse(over|out) are still within the same parent element
  var parent = event.relatedTarget;
  // Traverse up the tree
  while ( parent && parent != this )
//  alternate solution:
    try {
      var s = HTMLElement.prototype.toString.call(parent);
      if (s == '[xpconnect wrapped native prototype]' || // FF 3.5 check
          s == '[object XULElement]') {                  // FF < 3.5 check
        return;
      }
      parent = parent.parentNode;
    }
    catch(e) { parent = this; }
  if( parent != this ){
    // set the correct event type
    event.type = event.data;
    // handle event if we actually just moused on to a non sub-element
    jQuery.event.handle.apply( this, arguments );
  }
};


//WrapImgs and hover
$(".imgs").wrap('<div class="wrapImgD"></div>');

    $('.wrapImgD').hover(
    function(e) {
      e.preventDefault();
      var $img = $(this).find('.colorimg');	
      $img.animate({opacity: 1}, 300);
    },
    function(e) {
      e.preventDefault();
      var $img = $(this).find('.colorimg');	
      $img.animate({opacity: 0}, 300);
    }	
  );


//Switcher

var $activeA = $('#js-switchVisualProject li a.active').attr('id').substr(2);

	$('.workers').hide();	
	$('#work'+$activeA).show();
	$('.desc-proj').hide();	
	$('#description'+$activeA).show();


    $('#js-switchVisualProject li a').click(function(e) {
    e.preventDefault();
    if ($(this).attr('id')!='mp') {
      location.hash = $(this).attr('href').replace(/^.*#/, '');
    } else {
      location.href = $(this).attr('href');
    }	

  	var $link = $(this);
  	var $alink =  $('#js-switchVisualProject li a');
  		
  	$alink.removeClass('active');	
  	$link.toggleClass('active');  
  
  	var $linkid = $(this).attr('id').substr(2); 
  	var $linkclass = $(this).attr('class'); 

	$('.workers').hide();	
	$('#work'+$linkid).show();
	$('.desc-proj').hide();	
	$('#description'+$linkid).show();	



  	var $linkidTx = $(this).attr('id');
	if ($linkidTx == 'date') {
  	  $('#description1').addClass('hide1');
  	  $('#description2').addClass('hide1');	
  	  $('#description').removeClass('hide1');
  	  $('#projimg img').attr('src', '/images/inner/right-already1.gif');
  	} else if ($linkidTx == 'aboutpr') {
  	  $('#description').addClass('hide1');
  	  $('#description2').addClass('hide1');	
  	  $('#description1').removeClass('hide1');
  	  $('#projimg img').attr('src', '/images/inner/right-already2.gif');
  	} else if ($linkidTx == 'all') {
  	  $('#description').addClass('hide1');
  	  $('#description1').addClass('hide1');	  
  	  $('#description2').removeClass('hide1');
  	  $('#projimg img').attr('src', '/images/inner/right-already2.gif');
  	} 


});

   
  var locationElems = location.hash.toString().replace(/^.*#/, '').split('.');
  
  var linksToclick = [];
  while(locationElems.length){
    linksToclick.push(locationElems.join('.'));
    locationElems.pop();
  }
  
  while(linksToclick.length){
    var linkToClick = linksToclick.pop();
    if(!linkToClick)break;
    
    $('a[href$='+linkToClick.replace('.', '\\.')+']').trigger('click');
  }

  $("#byType").addClass("active semiactive");

});


