function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
     anchor.target = "_blank";
   }
 }
}

var newwindow;
function popupWindow(url,name,width,height)
{
	newwindow=window.open(url,'name','height='+height+',width='+width+',resizable=true,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}



$(document).ready(function() {

	function formatTitle(title, currentArray, currentIndex, currentOpts) {
	    return '<div id="fancy-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/site/img/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}
	
	function formatTitleInd(title, currentOpts) {
	    return '<div id="fancy-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/site/img/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) +'</div>';
	}

	/*function formatTitle(title, currentArray, currentIndex, currentOpts) {
	    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/site/img/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}*/
	
	
	
	$("#wall .item a.thumb").fancybox({
	    'showCloseButton'   : false,
		'titlePosition' 	: 'inside',
		'titleFormat'		: formatTitleInd
	});
	
	$(".fancy").fancybox({
	    'showCloseButton'   : false,
		'titlePosition' 	: 'inside',
		'titleFormat'		: formatTitle
	});

	$('ul.sf-menu').supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
        }).superfish();

	$('#wall .reply:even').addClass('alt');
	$('table.stripe tr:even').addClass('alt');
	
	//$('#wall .post:odd').addClass('alt');

	//$('#wall .item a.thumb').fancybox();
	
//	$('body#gallerypage ul#thumbs a').fancybox();
	
	
	$.fn.qtip.styles.mystyle = { // Last part is the name of the style
	   
   	   width: 200,
	   background: '#736c63',
	   color: '#f3f2e5',
	   textAlign: 'center',
	   border: {
		  width: 7,
		  radius: 5,
		  color: '#736c63'
	   },
	   tip: 'topLeft',
	   name: 'dark' // Inherit the rest of the attributes from the preset dark style
	}

	$("a.helptip[title]").qtip({
	   style: 'mystyle', // The name of the newly created custom style above
	   show: 'mouseover',
   	   hide: 'mouseout',
   	   tip: true
   	   });
	
	
	$('body#homepage #photos').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:         8000,  // milliseconds between slide transitions (0 to disable auto advance) 
		speed:           2000  // speed of the transition (any valid fx speed value) 
	});
	
	$('body#experiencestep3page #photos').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:         3000,  // milliseconds between slide transitions (0 to disable auto advance) 
		speed:           2000  // speed of the transition (any valid fx speed value) 
	});
	
	function make_elem(type, contents) {
      var elem = document.createElement(type);
      if (contents != undefined)
          elem.appendChild(document.createTextNode(contents));
      return jQuery(elem);
    
  }

  $("#designstyle :radio").change(function() {
    var src =  $(this).closest('li').find('img').attr('src');
    var type = $(this).attr('class');
    var collage_img = $("#collage li#" + type + " img");
    if (collage_img.length)
	collage_img.attr('src', src);
    else
      $("#collage li#" + type).append(make_elem('img').attr({src: src, width: 85}));
  });

	

});



