// !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: 500, link: 'cancel', transition: 'quad:out' }).hide();
			var subFx = new Fx.Tween(item, { duration: 500, 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();
			    }
			});
		}
	});
});






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







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() {
	// setup the currency selection window
	var cur = {};
	cur = new MultiBox('cur', {openFromLink: false, useOverlay: false, showControls: false});
	
});

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];
  }
}



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





window.addEvent('domready', function(){

	if($('recent')){
				
		var slides = Math.ceil($$('div.viewed').length / 4);		// NUMBER OF SLIDES IN SLIDESHOW
		var pos = 0;
		var offset = 650;	// HOW MUCH TO SLIDE WITH EACH CLICK
		var currentslide = 1;	// CURRENT SLIDE IS THE FIRST SLIDE
										 
		var recentscroll = new Fx.Scroll('recentWrap', {
			offset: {'x': 0, 'y': 0},
			transition: Fx.Transitions.Cubic.easeOut	// HOW THE SCROLLER SCROLLS
		}).toLeft();
		
		if(slides <= 1 ){
			$('moveright').set('styles', {'visibility': 'hidden'});
			$('moveleft').set('styles', {'visibility': 'hidden'});
		}
		
		if (currentslide == 1) $('moveleft').set('styles', {'visibility': 'hidden'});		
	
		/* EVENTS - WHEN AN ARROW IS CLICKED THE THUMBNAILS SCROLL */
		$('moveleft').addEvent('click', function(event) { event = new Event(event).stop();
			//alert('moveleft');
			if(currentslide == 1) return;
			currentslide--;					// CURRENT SLIDE IS ONE LESS
			pos += -(offset);				// CHANGE SCROLL POSITION
			recentscroll.start(pos);			// SCROLL TO NEW POSITION
			if (currentslide == 1){
				var element = $('moveleft');
				var fadeOut = new Fx.Tween(element);		
				fadeOut.start('opacity', '1', '0');
				
				var element2 = $('moveright');
				var fadeIn = new Fx.Tween(element2);
				fadeIn.start('opacity', '0' , '1');
				
			}
			if (currentslide > 1) {
				var element = $('moveright');
				var fadeIn = new Fx.Tween(element);		
				fadeIn.start('opacity', '0', '1');	
			}			
		});
		$('moveright').addEvent('click', function(event) { event = new Event(event).stop();
			//alert(currentslide);
			if(currentslide >= slides) return;
			currentslide++;
			pos += offset;
			recentscroll.start(pos);
			if (currentslide > 1)  {
				var element = $('moveleft');
				var fadeIn = new Fx.Tween(element);		
				fadeIn.start('opacity', '0', '1');	
			}		
			if (currentslide == slides) {
				var element = $('moveright');
				var fadeIn = new Fx.Tween(element);		
				fadeIn.start('opacity', '1', '0');
			}
		});
	};
});

