

var fixedfooterscroll //defined here so it can be set up in the domready function but still be available


window.addEvent('domready', function(){
	
	//Tips
	var myTips = new Tips('.Tips1');
	
	//implement new element effects and events
	
	Element.implement({
		//implement centre
		centreEl: function() {
			//have to set display block otherwise has no height
			
			this.setStyles({opacity:0, 'display':'block'});
			elSc = window.getScroll();
			elsize = this.getSize()
			var postop = window.getSize()
			
			postopmiddle = (elSc.y+(postop.y/2)) - (elsize.y/2)
			posleftmiddle = (postop.x/2) - (elsize.x/2)
			
			//need to check to see if the element height is larger then the portal
			if (postopmiddle<0){postopmiddle = 0};
			this.setStyles({'top':postopmiddle+'px', 'left':posleftmiddle+'px'});
			
		},
		
		centreElFade: function() {
			
			this.setStyles({opacity:0, 'display':'block'});
			elSc = window.getScroll();
			elsize = this.getSize()
			var postop = window.getSize()
			postopmiddle = (elSc.y+(postop.y/2)) - (elsize.y/2)
			posleftmiddle = (postop.x/2) - (elsize.x/2)
			
			//need to check to see if the element height is larger then the portal
			if (postopmiddle<0){postopmiddle = 0};
			//el.setStyles({'top':top+'px', 'left':left+'px'});
			this.setStyles({'top':postopmiddle, 'left':posleftmiddle});
			this.fade('in');
			//make sure block is back on if its gone away
			//doesnt work cos the fade hasnt finished need to create my own chain
			//here if you want to do it like this
			/*currentStyle = this.getStyle('visibility')
			if (currentStyle = 'hidden'){
				alert(currentStyle)
				//this.setStyles({'display':'none'})
			}
			//elParent = this.getParent();
			//elParent.setStyles({'height':'auto'});
			*/

		},
		//implement a block level fade
		fadeToggleBlock: function () {
		
			currentStyle = this.getStyle('display')
			if (currentStyle == 'block'){
				//we are fading out
				//no point fading out unless chaining as it will switch ti display none immediately
				//this.fade('out');
				this.setStyles({'display':'none'});
			}else{
				this.setStyles({opacity:0, 'display':'block'});
				this.fade('in');
			}
			
			
		},
		
		//implement show
		fadeShow: function() {
			//set display:none and opacity 0
			this.setStyles({opacity:0, 'display':'block'});
			this.fade('in');
		},
		//implement fade toggle
		fadeShowTog: function() {
			//set display:none and opacity 0
			this.setStyles({opacity:0, 'display':'block'});
			this.fade('toggle');
		},

		fadeShowNB: function() {
			//set display:none and opacity 0
			this.setStyles({opacity:0, 'visibility':'visible'});
			this.fade('in');
		},
		//implement hide
		fadeHide: function() {
			var style = this.getStyle('opacity');
			if (style=100){
			this.fade('out');
			};
			//this.setStyles({opacity:0, 'display':'block'});

		},
		
		ElFadeDestroy: function(){
			
			
			this.fade('out').get('tween').chain(function() { this.destroy(); }); 

			
			/*var myChain = new Chain();
			
			myChain.chain(
			function(el) {this.fade('out'); this.callChain();},
			function(el) {this.dispose(); this.callChain();}
			);
			
			myChain.callChain(this);*/		
		},
		
		highlight: function(search, insensitive, klass){
				var regex = new RegExp('(<[^>]*>)|('+ search.escapeRegExp() +')', insensitive ? 'ig' : 'g');
				return this.set('html', this.get('html').replace(regex, function(a, b, c){
					return (a.charAt(0) == '<') ? a : '<strong class="'+ klass +'">' + c + '</strong>'; 
				}));
		},
		
		highlightToEnd: function(search, insensitive, klass){
				
				myA = this.get('html').split(search,2);
				myStr = this.get('html')
				
				if (this.get('html').contains(search)){
					myStr = myStr.replace(search, '<strong class="'+ klass +'">' + search)
					myStr = myStr + '</strong>'
					
					this.flash('#FF9999', '#fff', null, null,1000)
					
					return this.set('html', myStr)
				}
				if ( $chk(myA[1]) ){
				//also have to check for the length of the array	
					//set up a tween..?  
					//make up new string
					//myStr = myStr.replace(search, '<strong class="'+ klass +'">' + search)
					//myStr = myStr + '</strong>'
					
					//this.flash('#FF9999', '#fff', null, null,1000)
					
					//return this.set('html', myStr)
				
				};
				
		},
		
		flash: function(to,from,reps,prop,dur) {
			
			//defaults
			if(!reps) { reps = 1; }
			if(!prop) { prop = 'background-color'; }
			if(!dur) { dur = 250; }
			
			//create effect
			var effect = new Fx.Tween(this, {
					duration: dur,
					link: 'chain'
				})
			
			//do it!
			for(x = 1; x <= reps; x++)
			{
				effect.start(prop,from,to).start(prop,to,from);
			}
		}
		
		
		
	});
	
	/* PREPARE TOGGLE TARGETS  */
	$each($$('.toggleTgt'),function(el){el.setStyles({ 'opacity':0 , 'display': 'none' });});


	//fixedfooterscroll = new Fx.Style('openbasket', 'bottom', {duration:500, transition: Fx.Transitions.Quad.easeOut});


	$$('.toggling').addEvent('click', function(e) {
	
	/*this function will act on the click event of any element
	with the class name of 'toggling'
	ensure the element to be toggled has the same ID
	as the clicked element prefixed with 'open_'  
	
	If unique IDs are required for two or more clickable elements
	to act on ONE action element then suffix the clicked ID with ':whatever'
	the suffix will be removed
	
	If you wish to control the behaviour of the toggle add
	|hide |show to the end and it will hide or show or default to toggle if nothing is there
	
	If you wish to define that it is a visibility rather than a display then put |visibility
	otherwise it will default to block
	*/
	
	//e = new Event(e).stop();
	
	//create the text string for the clicked element
	//IE doesnt have target Mozilla doesnt have srcElement
	
	var tgt = e.target || e.srcElement; // IE doesn't use .target
	var elClickedstr = tgt.id;
	
	//this will find any | so we can chop it off to get the actioned element part of the string
	pos = elClickedstr.indexOf(':');
	
	//capture that ID as an object
	if (pos !=-1){el=$("open_" + elClickedstr.substring(0,pos));}
	
	else {el=$("open_" + elClickedstr);}
	
	//also want to add in a switch to say if it should hide|show|toggle
	if (elClickedstr.indexOf('visibility') != -1) {
							 
		if (elClickedstr.indexOf('hide') != -1) {el.style.visibility = 'hidden';}
		else if (elClickedstr.indexOf('show') != -1) {el.style.visibility = 'visible';}
		else {el.style.visibility = (el.style.visibility == 'hidden') ? 'visible' : 'hidden';}//just toggle it 
	}
	else {

		if (elClickedstr.indexOf('hide') != -1) {el.style.display = 'none';}
		else if (elClickedstr.indexOf('show') != -1) {el.style.display = 'block';}
		else {el.style.display = (el.style.display == 'none') ? 'block' : 'none'; }//just toggle it 
	};

	
							


	});



//now need to add an event for all class toggle baskets

$each($$('.togglebasket'), function(el){
	 //so if there is an rel= in the link AND (&&) el.rel.test(regular expression check)
	el.addEvent('click', function(e) {
		e.stop();
		elB = $('basketcontent')
		elB.style.top = ($('button_basket').getTop() ) + "px";
		elB.style.left = ($('kwicks').getLeft() + 200) + "px";
		elB.fadeShowTog();
		});
			
});


//order details rollover

$each($$('.orderdetails'), function(el){
	 //so if there is an rel= in the link AND (&&) el.rel.test(regular expression check)
		el.addEvent('click', fncOrderDetails.pass([el.id,1]));
		//el.addEvent('mouseleave', fncOrderDetailsHide.pass(el.id,0));
});


//adds a visual clue to focusing
$each($$('input[type=text]'), function(el){
							
el.addEvent('focus', function(e) {
	el.setStyle('background-color','#ffffdd');
							  });

el.addEvent('blur', function(e) {
	el.setStyle('background-color','');
							  });


});

//adds a visual clue to psuedo js links
$each($$('.psuedolink'), function(el){
	
	el.addEvent('mouseenter', function(e) {
		el.setStyle('color','#900');
	
	});
	el.addEvent('mouseleave', function(e) {
		el.setStyle('color','');
	});

});




// sets up the top menu movement

 var kwicks = new Kwicks('kwicks');


/*

var szNormal = 66, szSmall  = 66, szFull   = 120;
 
var kwicks = $$("#topmenu .topmenulinks");
var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
kwicks.each(function(kwick, i) {
	kwick.addEvent("mouseenter", function(event) {
		var o = {};
		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
		kwicks.each(function(other, j) {
			if(i != j) {
				var w = other.getStyle("width").toInt();
				if(w != szSmall) o[j] = {width: [w, szSmall]};
			}
		});
		fx.start(o);
	});
});
 
$("topmenu").addEvent("mouseleave", function(event) {
	var o = {};
	kwicks.each(function(kwick, i) {
		o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
	});
	fx.start(o);
})

*/

//end top menu




function myextrainfo(obj){
	obj.style.display = '';
}


}); //end of dom ready function


//sets up kwicks
var Kwicks = new Class({
  
  Implements: [Options],
  
  options: {
    squeezeWidth: 66,
    maxWidth: 120
  },
  
  initialize: function(list,options) {
    this.setOptions(options);
    this.list = document.id(list);
    this.parse();
  },
  
  parse: function() {
    //vars
    var items = this.list.getElements('a'),
      fx = new Fx.Elements(items, {wait: false, duration: 250, transition:Fx.Transitions.Cubic.easeOut}),
      startWidths = [],
      options = this.options;
    //kwicks items
    items.each(function(item,i) {
      startWidths.push(item.getStyle('width').toInt());
      item.addEvent('mouseenter',function(){
        var fxSettings = {};
        fxSettings[i] = {
          'width': [item.getStyle('width').toInt(),options.maxWidth]
        };
        items.each(function(sibling,ii) {
          if(sibling != item) {
            var w = sibling.getStyle('width').toInt();
            if (w != options.squeezeWidth) {
              fxSettings[ii] = {
                'width': [w,options.squeezeWidth] 
              };
            }
          }
        },this);
        fx.start(fxSettings);
      },this);
    },this);
    //list
    this.list.addEvent('mouseleave',function() {
      var fxSettings = {};
      items.each(function(item,i) {
        fxSettings[i] = {
          width: [item.getStyle('width').toInt(), startWidths[i]]
        };
      });
      fx.start(fxSettings);
    });
  }
});





//URCHIN ANALYTICS
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-8824014-1");
pageTracker._trackPageview();
} catch(err) {}



