//Function to perform mouseover effect for li:hover in IE 
navHover = function() {
	
	var sfEls = document.getElementById("mainnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);


window.addEvent('domready', function(){
	if($('zoom')){
		var el = $$('div.dot');
		$$('div.dot').addEvents({
			mouseenter: function(){
				MagicZoom_stopZooms();			
			},
			mouseleave: function(){
				if(!$('zoom1')) return false;
				if(!$('zoom1').getFirst('img')) return false;
				var zoomimage = $('zoom1').getFirst('img').get('src');
				//zoomimage.set('src', zoomimage.get('src'));
				var newimage = $('zoom1').get('href');			
				$('zoom').innerHTML = '<a id="zoom1" href="' + newimage + '" rel="zoom-position: inner; zoom-width:285px; zoom-height:240px" class="MagicZoom"><img src="' + zoomimage + '" /></a>';
				var tim = setTimeout('findZooms()', 300);
			}
		});
		findZooms = function() {		
			MagicZoom_findZooms();
		}
	}
});

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

	if($('recent')){
				
		var slides = Math.ceil($$('div.viewed').length / 3);		// 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');
			}
		});
	};
});

window.addEvent('domready', function(){
	
	if($('subnavWrap')){
		var active = false;
		var visible = 270;
		var height = $('subnav').getSize().y;
		var position = 0;
		// if we have more items than room
		if(height > visible){
			// this reactivates the menu
			function reactivate(){ active = false; }
			
			// set display styles & morph effect
			$('subnavWrap').set('styles', { 'height': visible, 'overflow': 'hidden', 'position': 'relative'});
			var subnavEffect = new Fx.Morph('subnav', {duration: 'long'});
			subnavEffect.set({'height': visible, 'position': 'absolute', 'top': 0});
			subnavEffect.addEvent('complete', reactivate);
			
			// create a link for less items & add after the subnav
			var lessLink = new Element('a', {
				'href': '#',
				'class': 'lessLink',
				'html': 'Less',
				'events': {
					'click': function(e){				
						e = new Event(e);
						moreOrLess('less');
						e.stop();
					}
				}
			});
			lessLink.inject($('subnavWrap'), 'after');
			
			// create a link for more items & add after the subnav
			var moreLink = new Element('a', {
				'href': '#',
				'class': 'moreLink',
				'html': 'More',
				'events': {
					'click': function(e){				
						e = new Event(e);
						moreOrLess('more');
						e.stop();
					}
				}
			});
			moreLink.inject($('subnavWrap'), 'after');
			
			// this is the brains of it
			function moreOrLess(action){
				if(active == false){
					// calulate position
					var pos = $('subnav').getStyle('top').toInt();
					
					// perform actions
					if(action == 'more'){
						subnavEffect.start({'top': pos - visible});
						position += visible;
						active = true;
					}
					if(action == 'less'){
						subnavEffect.start({'top': pos + visible});
						position -= visible;
						active = true;
					}
					
					// determine position and what actions to display
					if(position > (height-visible)){
						lessLink.set('styles', {'display': ''});
						moreLink.set('styles', {'display': 'none'});
					}else if(position == 0){
						lessLink.set('styles', {'display': 'none'});
						moreLink.set('styles', {'display': ''});
					}else{
						lessLink.set('styles', {'display': ''});
						moreLink.set('styles', {'display': ''});
					}
				}
			}
			// initialise
			moreOrLess();
		}
	}
	
});


window.addEvent('domready', function(){
	if($('background')){
		var mySlide = new Fx.Slide('background');
		mySlide.hide();
		$('toggled').addEvent('click', function(e){
			e = new Event(e);
			mySlide.toggle();
			e.stop();
		});	
	}
});


window.addEvent('domready', function(){
	if($('product_info')){
		var mySlide = new Fx.Slide('product_info');
		mySlide.hide();
		$('toggle').addEvent('click', function(e){
			e = new Event(e);
			mySlide.toggle();
			e.stop();
		});	
	}
});

//BookMarker
function bookmark(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "");
}

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

//Form Validation
function checkform ( form )
{
	if (form.your_name.value == "") {
   alert( "Please enter your Name." );
   form.your_name.focus();
   return false ;
	}
}