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"; 
} 
} 

function fieldFocus() {
	if (!document.getElementsByTagName) return;
	var textboxes = document.getElementsByTagName('input');
	var textareas = document.getElementsByTagName('textarea');
	var selects = document.getElementsByTagName('select');
	function change(obj,style,styleon) {
		if (obj.className == style) {
			obj.onfocus = function() {this.className == style ? this.className = styleon : this.className = style;}
			obj.onblur = function() {this.className == styleon ? this.className = style : this.className = styleon}
		}	
	}
	for (var i=0; i<textboxes.length; i++) {
		var textbox = textboxes[i];
		change(textbox,"textfield","textfieldon");
	}
	for (var i=0; i<textareas.length; i++) {
		var textarea = textareas[i];
		change(textarea,"textfield","textfieldon");
	}	
	for (var i=0; i<selects.length; i++) {
		var select = selects[i];
		change(select,"textfield","textfieldon");
	}
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll,r){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+r+''
	win = window.open(mypage,myname,settings)
}

function confirmDelete(name) {
if (confirm("Really Delete Image "+name+"?")) return true;
else return false;
}

function format_sel(v) {
  var str = document.selection.createRange().text;
  document.myform.editarea.focus();
  var sel = document.selection.createRange();
  sel.text = "<" + v + ">" + str + "</" + v + ">";
  return;
}
function insert_link() {
  var str = document.selection.createRange().text;
  document.myform.editarea.focus();
  var my_link = prompt("Enter URL:","http://");
  if (my_link != null) {
    var sel = document.selection.createRange();
	sel.text = "<a href=\"" + my_link + "\">" + str + "</a>";
  }
  return;
}

$(function() {
	fieldFocus();
	externalLinks();

  (function() {
	var gallery = {   
	  carousel: null,
	  
	  init: function () {
	    this.carousel = $('#gallery');
	  
	    if (!this.carousel.length) {
		  return;	
		}
	  
		this.carousel.jcarousel();
		this.configure();
	  },
	  
	  configure: function() {
	    var self = this;
		
		this.carousel.find('a').hover(function() { 
			$(this).css('background', '#f7f7f7').find('img').animate({ opacity: 0.5 }, 300); 
		}, 
		function() { 
			$(this).css('background', '#ffffff').find('img').animate({ opacity: 1 }, 300); 
		});
	  }
	};
	
	gallery.init();  
  })();	
});