$(document).ready(function(){
    $('dt.gallery-icon a').each(
      function(){
        $(this).attr('rel', 'gallery');
      }
    );

  $("dt.gallery-icon a").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'titlePosition' : 'inside'
	});
	
	$("a.iframe").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'titlePosition' : 'inside',
		'width' : 640,
		'height' : 480
	});
	
	$(window).bind("resize scroll", function(){
	  stripe();
	});
	
	$("#social a img").each(function(){
	  var className = $(this).attr("class");
	  
	  $(this).hover(function(){
	      $(this).attr("src", stylesheet_directory + "/img/" + className + "_hover.png");
	    },
	    function(){
	      $(this).attr("src", stylesheet_directory + "/img/" + className + "_normal.png");
	    }
	  );
	});
	
	$("ul.fix-vertical li").each(function(){
	  
	  try{
	    var height = $(this).find(".float-left").height();
	    var fheight = $(this).find(".float").height();
	    
	    
	    if (height != fheight){
	      var half = (height - fheight) / 2;
	      $(this).find(".float").css("margin-top", half);
	    }
	  }catch(e){}
	});
	
	
	// Fix aligment
	var farest = $(document).width();
	
	$("ul.fix-vertical li span.ls").each(function(){
    var offset = $(this).offset();
    farest = offset.left < farest ? offset.left : farest;
	}).each(function(){
	  var offset = $(this).offset();
	  $(this).css("margin-right", offset.left - farest);
	  
	  // WTF IE?
	  if ($.browser.msie){
	  var a = $(this);
	  setTimeout(function(){
	   a.css("display", "block");
	   setTimeout(function(){
	     a.css("display", "inline");
	   },1);
	   
	   },1);
    }
	});
	
});

$(window).load(function(){
  stripe();
});

function term(a){
  try{
    console.log(a);
  }catch(e){}
}

function stripe(){
  $(".stripe-away").each(function(){
    $(this).remove();
  });
  
  $(".stripe").each(function(){
    
	  var doc_width = $(document).width();
	  var con_width = $("#wrapper").width();
    var off_this = $(this).offset();
    var offset = /stripe\-(\d+)/i.exec($(this).attr("class"));
	  var side_size = doc_width - con_width;
	  var half_size = (side_size / 2) * 1.2;
	  
	  $("body").append("<div class='stripe-away' style='width: " + half_size + "px; margin-left: -" + half_size + "px; left: " + off_this.left + "px; top: " + (off_this.top + (offset != null ? parseInt(offset[1]) : 0)) + "px;'></div>");
	  
	});
}

