// !Subnav control
window.addEvent('domready', function() {
	$$('.flood').each(function(item, index){	
		var div = item.getParent('.subnav');
		var li = div.getParent();
		if(div && li){
			div.setStyle('display', 'block');
			var sub = new Fx.Slide(item, { duration: 200, link: 'cancel', transition: 'quad:out' }).hide();
			var subFx = new Fx.Tween(item, { duration: 200, link: 'cancel' });
			li.addEvents({
		    	'mouseenter': function(){
			    	this.addClass('hover');
			    	subFx.cancel();
			    	sub.cancel();
			    	subFx.set('opacity', 1);
			    	sub.slideIn();
			    },
			    'mouseleave': function(){
			    	this.removeClass('hover');
			    	subFx.cancel();
			    	sub.cancel();
			     	subFx.start('opacity', 0);
			     	sub.slideOut();
			    }
			});
		}
	});
});














window.addEvent('domready', function(){
			/* Tips 2 */
			var Tips2 = new Tips($$('.Tips2'), {
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
			});
}); 



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


// 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");
  }
}

// Lightboxes
window.addEvent('domready', function() {
	$$('.mb, .cur').each(function(a, i){
		if(a.get('rel').contains('ajax:true')){
			if(a.get('href').contains('?')){
				a.set('href', a.get('href') + "&lightbox=true");
			}else{
				a.set('href', a.get('href') + "?lightbox=true");
			}
		}
		if(a.get('rel').contains('iframe:true')){
			if(a.get('href').contains('?')){
				a.set('href', a.get('href') + "&iframe=true");
			}else{
				a.set('href', a.get('href') + "?iframe=true");
			}
		}
	});
	var box = {};
	box = new MultiBox('mb', {useOverlay: false, showControls: false});	
});


// ! Currency lightbox

window.addEvent('domready', function() {
									 
	var curID = getUrlParameter('currencies_id');
	
	var cur = {};
	
	// Check if we have a currency ID in the URL
	if(curID) {
	  Cookie.write('curid', curID, { path: "/" });
	  cur = new MultiBox('cur', {openFromLink: false, useOverlay: false, showControls: false});
	  return true;
	}  
	
	
	
	// Check if we have a currency in the cookie
  	cookieCurID = Cookie.read('curid');
	
	if(cookieCurID) {
		cur = new MultiBox('cur', {openFromLink: false, useOverlay: false, showControls: false});
		return true;
	}else{
		cur = new MultiBox('cur', {openFromLink: false, useOverlay: false, showControls: false});
		//cur.open($('curSelect'));
		return true;
	}
	
	
	
	// No currency so fire the currency select window
	/*var cur = {};
	cur = new MultiBox('cur', {openFromLink: false, useOverlay: false, showControls: false});
	cur.open($('curSelect'));*/

});



	
function getUrlParameter( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
	  return "";
	} else {
	  return results[1];
  }
} 

















// !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);
			}
		}
	}
});



