// Pop Up Window
var newwindow;
function popup(url){
	newwindow=window.open(url,'name','height=580,width=560, scrollbars=yes, toolbar=no, menubar=no, resizable=yes');
	if (window.focus) {newwindow.focus()}
}


// Open Pop-Up Window
function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}


function showPic(whichpic,whichurl) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  var placeholderlink = document.getElementById("placeholderlink");
  placeholder.setAttribute("src",source);
  placeholderlink.setAttribute("href",whichurl);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
//  if (description.firstChild.nodeType == 3) {
//    description.firstChild.nodeValue = text;
//  }
//  return false;
}



// Bookmarking
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  	window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

// !Subnav
window.addEvent('domready', function() {
	var mySmoothScroll = new SmoothScroll({links: '.smoothAnchor'});
	
	var subnavs = $$('.subnav');
	subnavs.each(function(subnav, index){
		var link = subnav.getParent();
		if(link){
			subnav.setStyle('display', 'block')
			var subFx = new Fx.Tween(subnav, {duration: 300, property: 'opacity'});
			subFx.set(0);
			link.addEvents({
		    'mouseenter': function(){
		    	this.addClass('hover');
		    	subFx.cancel();
		    	subFx.start(1);
		    },
		    'mouseleave': function(){
		      this.removeClass('hover');
		      subFx.cancel();
		      subFx.start(0);
		    }
			});

		}
		
	});
	
});






// !show/hide tab management
window.addEvent('domready', function(){
	var tablinks = $$('#tabs a');
	var tabmodifier = "-tab";
	var currentTab;
	if(tablinks){
		var activetabs = tablinks.filter(function(el){
		  var id = el.get('id');
		  if(id){ var tabcontent = $(id + tabmodifier); }
      if(tabcontent){
      	return el;
      }
		});
		
		activetabs.each(function(el) {
			el.set({
		    'events': {
	        'click': function(){ showTab(el); currentTab = el; return false; }
		    }
			});
			if(el.hasClass('current')){
				currentTab = el;
			}
		});
		
		if(!currentTab){
			hasHash = window.location.href.split("#");
			if(hasHash && hasHash[1]) {
				currentTab = $(hasHash[1].replace('-tab', ''));

			} else {
				currentTab = activetabs[0];
			}
		}
		showTab(currentTab)
	}
	
	function showTab(tab){
		activetabs.each(function(el) {
			var id = el.get('id');
		  if(id){ var tabcontent = $(id + tabmodifier); }
      if(tabcontent){
      	if(tab == el){
					el.set('class', 'current');
					tabcontent.set('class', 'tabcontent');
				}else{
					if(el.hasClass('current')){ el.removeClass('current'); }
					tabcontent.set('class', 'hide');
				}
      }
		});
		var account = $('accountform');
		if(account){
			var action = account.get('action').split("#");
			if(action && action[0]) {
				account.set('action', action[0] + "#" + tab.get('id') + tabmodifier);
			}
		}
	}
});



// !Lightboxes
window.addEvent('domready', function() {
	var mbox = new multiBox({ mbClass: '.mb' });	
});



