// JavaScript Document
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-6603064-4");
pageTracker._trackPageview();
} catch(err) {}
var dialopt = {autoOpen: true,bgiframe: true, resizable: false,height:550,width:450,modal: true,closeOnEscape: true,overlay: {backgroundColor: '#000',opacity: 0.8},close: function(event, ui) {$(this).dialog('destroy');}};

var dialopt2 = {autoOpen: true,bgiframe: true, resizable: false,height:280,width:450,modal: true,closeOnEscape: true,overlay: {backgroundColor: '#000',opacity: 0.8},close: function(event, ui) {$(this).dialog('destroy');}};
function genCode(_id,_size,_bg,_bd){
	$('#_code').html("&lt;a href='http://viewonblack.me/v/?_id="+_id+"&_size="+_size);
	if(_bg=='w'){
		$('#_code').html($('#_code').html()+"&_bg=w");
	}
	if(_bd=="n"){
		$('#_code').html($('#_code').html()+"&_bd=n");
	}
	$('#_code').html($('#_code').html()+"'&gt;[View on ");
	if(_bg=='w'){
		$('#_code').html($('#_code').html()+"White]&lt;/a&gt;");
	}else{
		$('#_code').html($('#_code').html()+"Black]&lt;/a&gt;");		
	}
	$('#_code').show();
	SelectText('_code');
	return false;
}
function SelectText(element) {
    var text = document.getElementById(element);
    if ($.browser.msie) {
        var range = document.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if ($.browser.mozilla || $.browser.opera) {
        var selection = window.getSelection();
        var range = document.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    } else if ($.browser.safari) {
        var selection = window.getSelection();
        selection.setBaseAndExtent(text, 0, text, 1);
    }
}
function genbut(){
  $(".fg-button:not(.ui-state-disabled)")
  .hover(
	  function(){ 
		  $(this).addClass("ui-state-hover"); 
	  },
	  function(){ 
		  $(this).removeClass("ui-state-hover"); 
	  }
  )
  .mousedown(function(){
		  $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
		  if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
		  else { $(this).addClass("ui-state-active"); }	
  })
  .mouseup(function(){
	  if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
		  $(this).removeClass("ui-state-active");
	  }
  });	
}
function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}
function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}
var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};

$(document).ready(function() {
    jQuery.preLoadImages("img/delicious.png","img/delicious_o.png","img/digg.png.png","img/digg_o.png","img/delicious.png.png","img/delicious.png_o.png","img/email.png","img/email_o.png","img/facebook.png","img/facebook_o.png","img/link.png","img/link_o.png","img/reddit.png","img/reddit_o.png","img/technorati.png","img/technorati_o.png","img/twitter.png","img/twitter_o.png","img/topbg.png");
	PreSimpleSwapOnload(); SimpleSwapSetup();
});
