
// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();


/*--------------------------------------------------------------------------
 *  BEGIN: lightbox code
 *--------------------------------------------------------------------------*/

/**
 * @author Ryan Johnson <ryan@livepipe.net>
 * @copyright 2007 LivePipe LLC
 * @package Control.Modal
 * @license MIT
 * @url http://livepipe.net/projects/control_modal/
 * @version 1.2.12
 */

if(typeof(Control) == "undefined")
	Control = {};
Control.Modal = Class.create();
Object.extend(Control.Modal,{
	loaded: false,
	responders: $A([]),
	overlay: false,
	container: false,
	current: false,
	ie: false,
	targetRegexp: /#(.+)$/,
	imgRegexp: /\.(jpe?g|gif|png|tiff?)$/,
	overlayStyles: {
		position: 'absolute',
		top: 0,
		left: 0,
		zIndex: 9998
	},
	load: function(){
		if(!Control.Modal.loaded){
			Control.Modal.loaded = true;
			Control.Modal.ie = (navigator.appName == 'Microsoft Internet Explorer');
			Control.Modal.overlay = $(document.createElement('div'));
			Control.Modal.overlay.id = 'modal_overlay';
			Object.extend(Control.Modal.overlay.style,Control.Modal.overlayStyles);
			Control.Modal.overlay.hide();
			Control.Modal.container = $(document.createElement('div'));
			Control.Modal.container.id = 'modal_container';
			Control.Modal.container.hide();
			document.getElementsByTagName('body')[0].appendChild(Control.Modal.overlay);
			document.getElementsByTagName('body')[0].appendChild(Control.Modal.container);
		}
	},
	open: function(contents,options){
		m = new Control.Modal(false,$H({contents:contents}).merge(options));
		m.open();
		return m;
	},
	close: function(){
		if(Control.Modal.current)
			Control.Modal.current.close();
	},
	attachEvents: function(){
		Event.observe(window,'load',Control.Modal.load);
		Event.observe(window,'unload',Event.unloadCache,false);
	},
	center: function(){
		element = this.container;
		if(!element._centered){
			this.container.setStyle({
				position: 'absolute'
			}); 
			this.container._centered = true;
		}
		dimensions = Control.Modal.container.getDimensions();
		Position.prepare();
		offset_left = (Position.deltaX + Math.floor((Control.Modal.getWindowWidth() - dimensions.width) / 2));
		offset_top = (Position.deltaY + Math.floor((Control.Modal.getWindowHeight() - dimensions.height) / 2));
		modal_dimensions = Control.Modal.container.getDimensions();
		Control.Modal.container.setStyle({
			top: ((modal_dimensions.height <= Control.Modal.getWindowHeight()) ? ((offset_top != null && offset_top > 0) ? offset_top : '0') + 'px' : 0),
			left: ((modal_dimensions.width <= Control.Modal.getWindowWidth()) ? ((offset_left != null && offset_left > 0) ? offset_left : '0') + 'px' : 0)
		});
	},
	getWindowWidth: function(){
		return (self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0);
	},
	getWindowHeight: function(){
		return (self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0);
	},
	getDocumentWidth: function(){
		return Math.max(document.body.scrollWidth,Control.Modal.getWindowWidth());
	},
	getDocumentHeight: function(){
		return Math.max(document.body.scrollHeight,Control.Modal.getWindowHeight());
	},	
	onKeyDown: function(event){
		if(event.keyCode == Event.KEY_ESC)
			Control.Modal.close();
	},
	addResponder: function(responder){
		Control.Modal.responders.push(responder);
	},
	removeResponder: function(responder){
		Control.Modal.responders = Control.Modal.responders.without(responder);
	},
	//from Scriptaculous
	setOpacity: function(element,value){
		element= $(element);  
		if(value == 1){
			Element.setStyle(element,{
				opacity: (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : null
			});
		if(/MSIE/.test(navigator.userAgent))
			Element.setStyle(element,{
				filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')
			});  
		}else{  
			if(value < 0.00001) value = 0;  
			Element.setStyle(element, {opacity: value});
			if(/MSIE/.test(navigator.userAgent))  
				Element.setStyle(element,{
					filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') + 'alpha(opacity='+value*100+')'
				});  
		}
	}
});
Object.extend(Control.Modal.prototype,{
	mode: '',
	html: false,
	href: '',
	element: false,
	src: false,
	imageLoaded: false,
	initialize: function(element,options){
		this.element = $(element);
		this.options = $H({
			beforeOpen: Prototype.emptyFunction,
			afterOpen: Prototype.emptyFunction,
			beforeClose: Prototype.emptyFunction,
			afterClose: Prototype.emptyFunction,
			beforeLoad: Prototype.emptyFunction,
			onLoad: Prototype.emptyFunction,
			onFailure: Prototype.emptyFunction,
			onException: Prototype.emptyFunction,
			afterLoad: Prototype.emptyFunction,
			beforeImageLoad: Prototype.emptyFunction,
			afterImageLoad: Prototype.emptyFunction,
			contents: false,
			image: false,
			imageTemplate: new Template('<img src="#{src}" id="#{id}"/>'),
			imageAutoDisplay: true,
			imageCloseOnClick: true,
			hover: false,
			iframe: false,
			iframeTemplate: new Template('<iframe src="#{href}" width="100%" height="100%" frameborder="0" id="#{id}"></iframe>'),
			evalScripts: true, //for Ajax, define here instead of in requestOptions
			requestOptions: {}, //for Ajax.Request
			overlayDisplay: true,
			overlayClassName: '',
			overlayCloseOnClick: true,
			containerClassName: '',
			opacity: 0.3,
			zIndex: 9998,
			width: null,
			height: null,
			offsetLeft: 0, //for use with 'relative'
			offsetTop: 0, //for use with 'relative'
			position: 'absolute' //'absolute' or 'relative'
		});
		if(options)
			for(o in options)
				this.options[o] = options[o];
		target_match = false;
		image_match = false;
		if(this.element){
			target_match = Control.Modal.targetRegexp.exec(this.element.href);
			image_match = Control.Modal.imgRegexp.exec(this.element.href);
		}
		if(this.options.contents){
			this.mode = 'contents';
		}else if(this.options.image || image_match){
			this.mode = 'image';
			this.src = this.element.href;
		}else if(target_match){
			this.mode = 'named';
			x = $(target_match[1]);
			this.html = x.innerHTML;
			x.remove();
			this.href = target_match[1];
		}else{
			this.mode = (this.options.iframe) ? 'iframe' : 'ajax';
			this.href = this.element.href;
		}
		if(this.element){
			if(this.options.hover){
				this.element.observe('mouseover',this.open.bind(this));
				this.element.observe('mouseout',this.close.bind(this));
			}else{
				this.element.onclick = function(){
					this.open();
					return false;
				}.bindAsEventListener(this);
			}
		}
		targets = Control.Modal.targetRegexp.exec(window.location);
		this.position = function(){
			Control.Modal.overlay.setStyle({
				height: Control.Modal.getDocumentHeight() + 'px',
				width: Control.Modal.getDocumentWidth() + 'px'
			});
			if(this.options.position == 'absolute')
				Control.Modal.center();
			else{
				yx = Position.cumulativeOffset(this.element);
				Control.Modal.container.setStyle({
					position: 'absolute',
					top: yx[1] + this.options.offsetTop,
					left: yx[0] + this.options.offsetLeft
				});
			}
		}.bind(this);
		if(this.mode == 'image'){
			this.afterImageLoad = function(){
				if(this.options.imageAutoDisplay && !window.opera)
					$('modal_image').show();
				this.position();
				this.notifyResponders('afterImageLoad');
			}.bind(this);
		}
		if(this.mode == 'named' && targets && targets[1] && targets[1] == this.href)
			this.open();
	},
	open: function(){
		if(!this.options.hover)
			Event.observe($(document.getElementsByTagName('body')[0]),'keydown',Control.Modal.onKeyDown);
		Control.Modal.current = this;
		if(this.notifyResponders('beforeOpen') === false)
			return;
		if(!this.options.hover){
			Control.Modal.overlay.setStyle({
				zIndex: this.options.zIndex
			});
			Control.Modal.setOpacity(Control.Modal.overlay,this.options.opacity);
		}
		Control.Modal.container.setStyle({
			zIndex: this.options.zIndex + 1,
			width: (this.options.width ? this.options.width + 'px' : ''),
			height: (this.options.height ? this.options.height + 'px' : '')
		});
		if(Control.Modal.ie && !this.options.hover){
			$A(document.getElementsByTagName('select')).each(function(select){
				select.style.visibility = 'hidden';
			});
		}
		Control.Modal.overlay.addClassName(this.options.overlayClassName);
		Control.Modal.container.addClassName(this.options.containerClassName);
		switch(this.mode){
			case 'image':
				this.imageLoaded = false;
				this.notifyResponders('beforeImageLoad');
				this.update(this.options.imageTemplate.evaluate({src: this.src, id: 'modal_image'}));
				this.position();
				if(this.options.imageAutoDisplay && !window.opera)
					$('modal_image').hide();
				if(this.options.imageCloseOnClick)
					$('modal_image').observe('click',Control.Modal.close);
				$('modal_image').observe('load',this.afterImageLoad);
				$('modal_image').observe('readystatechange',this.afterImageLoad);
				break;
			case 'ajax':
				this.notifyResponders('beforeLoad');
				options = $H({
					method: 'get',
					onSuccess: function(request){
						this.notifyResponders('onLoad',request);
						this.update(request.responseText);
						if(this.options.evalScripts)
							request.responseText.evalScripts();
						this.notifyResponders('afterLoad',request);
					}.bind(this),
					onFailure: this.options.onFailure,
					onException: this.options.onException
				});
				if(this.options.requestOptions)
					for(o in this.options.requestOptions)
						options[o] = this.options.requestOptions[o];
				new Ajax.Request(this.href,options);
				break;
			case 'iframe':
				this.update(this.options.iframeTemplate.evaluate({href: this.href, id: 'modal_iframe'}));
				this.position();
				break;
			case 'contents':
				this.update((typeof(this.options.contents) == 'function' ? this.options.contents.bind(this)() : this.options.contents));
				break;
			case 'named':
				this.update(this.html);
				break;
		}
		if(!this.options.hover){
			if(this.options.overlayCloseOnClick && this.options.overlayDisplay)
				Control.Modal.overlay.observe('click',Control.Modal.close);
			if(this.options.overlayDisplay)
				Control.Modal.overlay.show();
		}
		this.notifyResponders('afterOpen');
	},
	update: function(html){
		Control.Modal.container.update(html);
		this.position();
		Control.Modal.container.show();
		if(this.options.position == 'absolute'){
			Event.stopObserving(window,'resize',this.position,false);
			Event.stopObserving(window,'scroll',this.position,false);
			Event.observe(window,'resize',this.position,false);
			Event.observe(window,'scroll',this.position,false);
		}
	},
	close: function(){
		response = this.notifyResponders('beforeClose');
		if(response == false && response != null)
			return;
		if(this.mode == 'image'){
			if(this.options.imageCloseOnClick)
				$('modal_image').stopObserving('click',Control.Modal.close);
			$('modal_image').stopObserving('load',this.afterImageLoad);
			$('modal_image').stopObserving('readystatechange',this.afterImageLoad);
		}
		if(Control.Modal.ie && !this.options.hover){
			$A(document.getElementsByTagName('select')).each(function(select){
				select.style.visibility = 'visible';
			});			
		}
		if(!this.options.hover)
			Event.stopObserving(window,'keyup',Control.Modal.onKeyDown);
		Control.Modal.current = false;	
		Control.Modal.overlay.removeClassName(this.options.overlayClassName);
		Control.Modal.container.removeClassName(this.options.containerClassName);
		Event.stopObserving(window,'resize',this.position,false);
		Event.stopObserving(window,'scroll',this.position,false);
		if(!this.options.hover){
			if(this.options.overlayCloseOnClick && this.options.overlayDisplay)
				Control.Modal.overlay.stopObserving('click',Control.Modal.close);
			if(this.options.overlayDisplay)
				Control.Modal.overlay.hide();
		}
		Control.Modal.container.update('');
		Control.Modal.container.hide();
		this.notifyResponders('afterClose');
	},
	notifyResponders: function(event_name,argument){
		Control.Modal.responders.each(function(responder){
			if(responder[event_name])
				responder[event_name](argument);
		});
		response = this.options[event_name](argument);
		return response;
	}
});
Control.Modal.attachEvents();


/*--------------------------------------------------------------------------
 *
 *
 *  BEGIN: couponcodesweekly specific code
 *
 *
 *--------------------------------------------------------------------------*/


Event.observe(window, 'load', function() {

	iePngFix();

	// button hover states
	
	initInputImageHoverState($('searchSubmit'), 'http://couponcodesweekly.com/ui/im/buttons/search_on.gif');
	initInputImageHoverState($('searchSubmitHome'), 'http://couponcodesweekly.com/ui/im/buttons/searchHome_on.gif');

		
	var triggers = $$('div.socialTools input.submit.yes');
	for(var i=0; i<triggers.length; i++){
		trigger = triggers[i];
		initInputImageHoverState(trigger, 'http://couponcodesweekly.com/ui/im/buttons/vote_yes_on.gif');
	}

	var triggers = $$('div.socialTools input.submit.no');
	for(var i=0; i<triggers.length; i++){
		trigger = triggers[i];
		initInputImageHoverState(trigger, 'http://couponcodesweekly.com/ui/im/buttons/vote_no_on.gif');
	}

  // modal window triggers
 $$('a.modal').each(function(link){
      new Control.Modal(link,{
        opacity: 0.8
      });
  });

  // tooltips
  $$("div.coupon strong").findAll(function(node){
    return node.getAttribute('title');
  }).each(function(node){
    new Tooltip(node,node.title);
    node.removeAttribute("title");
  });

});

function iePngFix() {
	//	this will iterate with each element with the class 'ie-fix-opacity' and add an IE filter,
	//	replacing the background-image for the filter of that image
	var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		document.getElementsByClassName('ie-fix-opacity').each(function(poElement){
			// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
			if(poElement.src) {
				poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + poElement.src + "', sizingMethod='crop')";
				poElement.src = '/ui/blank.gif';
			} else {
				var cBGImg = poElement.currentStyle.backgroundImage;
				var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));				
				poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='crop')";
				poElement.style.backgroundImage = "none";
			}
		});
	}
}

function validateForm(form) {
	// does this form have any fields with a class of "required"?
	var fields = Form.getElements(form);
	var isFormValid = true;
	for(var i=0; i<fields.length; i++) {
		field = fields[i];
		field.removeClassName('invalid');
		if(field.hasClassName('required') && $F(field.id) == '') {
			field.addClassName('invalid');
			if(isFormValid) {
				Field.activate(field.id);
				errorMsg = 'Please enter a '+field.title;
			}
			isFormValid = false;
		}
	}
	if(!isFormValid) {
		Control.Modal.open('<div class="modalErrorMessage">'+errorMsg+'.</div>');
	}
	return isFormValid;
}

function closeModal() {
	if(Control.Modal) {
		Control.Modal.close();
	}
}
 

function initInputImageHoverState(element, hoverImage) {
	if(element) {
		var normalImage = element.src;
		Event.observe(element, 'mouseover', function() { element.src = hoverImage; })
		Event.observe(element, 'mouseout', function() { element.src = normalImage; })
		// preload
		newImage = new Image();
		newImage.src = hoverImage;
	}
}

function outputEmail() {
		var a = '@';
		document.write('<a href="mail'+'to:enquiries'+a+'couponcodesweekly.com">');
		document.write('Contact Us');
		document.write('</a>');
}


// AJAX STUFF


function castVote(site, account, vote) {
	new Ajax.Request('http://www.couponcodesweekly.com/vote_ajax.php?id='+account+'&site='+site+'&vote='+vote);
	var accountDiv = $('account'+account);
	if(vote == 'Y') {
     accountDiv.className += ' valid';
     var yesButton = $$('#account'+account+' input.submit.yes');
     yesButton[0].style.visibility = "hidden";
     var stats = $$('#account'+account+' td.stats');
     stats[0].innerHTML = '<span class="good">Worked!</span> Like to say thanks? <a id="tellAFriendLink" href="/tell-a-friend.php?coupon='+account+'">Tell a friend &raquo;</a>';
	   //stats[0].innerHTML = '<span class="good">Worked!</span> Like to say thanks? <a id="tellAFriendLink" href="/how-much-did-you-save.php?store='+site+'">Tell us what you saved &raquo;</a>';
	} else {
    new Effect.BlindUp(accountDiv);
	}
}


function activateComments(id) {
	if($('view')) {
		var cc = $('cc'+id);
    Effect.toggle(cc, 'slide');
	}
}

function new_captcha()
{
	// loads new captcha image
	if(document.getElementById) {
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Please reload page");
	}
}

function discussLink(domain) {
 window.location = '/discuss/'+domain;
}

function changeSubmissionType(submissionType) {
	$('fields_code').style.display = 'none';
	$('fields_printable').style.display = 'none';
	$('fields_tip').style.display = 'none';
	if(submissionType == 'code') $('fields_code').style.display = 'block';
	if(submissionType == 'printable') $('fields_printable').style.display = 'block';
	if(submissionType == 'tip') $('fields_tip').style.display = 'block';
}



var previousAdsProcessed = 0;

function output_google_ads(google_ads) {
  /*
  * This function is required and is used to display
  * the ads that are returned from the JavaScript
  * request. You should modify the document.write
  * commands so that the HTML they write out fits
  * with your desired ad layout.
  */
  var s = '';
  var i;
  
  /*
  * Verify that there are actually ads to display.
  */
  if (google_ads.length == 0) {
    return;
  }
  
  /*
  * If an image or flash ad is returned, display that ad.
  * Otherwise, build a string containing all of the ads and
  * then use a document.write() command to print that string.
  */
  
  s = '<div class="adsense">';
  
  if (google_ads[0].type == "flash") { // FLASH AD
  
    s += '<a href=\"' +
    google_info.feedback_url + '\" id="adsByGoogle">Ads by Google</a><br>' +
    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' +
    google_ad.image_width + '" HEIGHT="' +
    google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' +
    google_ad.image_url + '">' +
    '<PARAM NAME="quality" VALUE="high">' +
    '<PARAM NAME="AllowScriptAccess" VALUE="never">' +
    '<EMBED src="' +
    google_ad.image_url + '" WIDTH="' +
    google_ad.image_width + '" HEIGHT="' +
    google_ad.image_height +
    '" TYPE="application/x-shockwave-flash"' +
    ' AllowScriptAccess="never" ' +
    ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
  
  } else if (google_ads[0].type == "image") { // IMAGE AD
  
    s += '<div class="googleImageAd"><a href=\"' +
    google_info.feedback_url + '\" id="adsByGoogle">Ads by Google</a><br/> <a href="' +
    google_ads[0].url + '" target="_top" title="go to ' +
    google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
    google_ads[0].visible_url + '\';return true"><img border="0" src="' +
    google_ads[0].image_url + '"width="' +
    google_ads[0].image_width + '"height="' +
    google_ads[0].image_height + '" alt="Ad" /></a></div>';
  
  } else { // TEXT AD
  
    s += '<a href=\"' + google_info.feedback_url + '\" id="adsByGoogle">Ads by Google</a><br/>'
    for(i = 0; i < google_ads.length; ++i) {
      previousAdsProcessed++;
      s += '<div class="googleTextAd"><a href="' +
      google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
      google_ads[i].visible_url + '\';return true">' +
      google_ads[i].line1 + '</a><p>' +
      google_ads[i].line2 + '<br>' +
      google_ads[i].line3 + '</p><a class="googleAdUrl" href="' +
      google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
      google_ads[i].visible_url + '\';return true">' +
      google_ads[i].visible_url + '</a></div>';
    }

  }
  s += '</div>';
  document.write(s);
  if(google_ads[0].bidtype == "CPC") previousAdsProcessed = previousAdsProcessed + google_ads.length;
  return;
}



/* TOOLTIPS */

var Tooltip = Class.create();
Tooltip.prototype = {
  initialize: function(element, tool_tip) {
    var options = Object.extend({
      default_css: false,
      margin: "0px",
	    padding: "5px",
	    backgroundColor: "#d6d6fc",
	    min_distance_x: 5,
      min_distance_y: 5,
      delta_x: 0,
      delta_y: 0,
      zindex: 1000
    }, arguments[2] || {});

    this.element      = $(element);

    this.options      = options;
    
    // use the supplied tooltip element or create our own div
    if($(tool_tip)) {
      this.tool_tip = $(tool_tip);
    } else {
      this.tool_tip = $(document.createElement("div")); 
      document.body.appendChild(this.tool_tip);
      this.tool_tip.addClassName("tooltip");
      this.tool_tip.appendChild(document.createTextNode(tool_tip));
    }

    // hide the tool-tip by default
    this.tool_tip.hide();

    this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
    this.eventMouseOut   = this.hideTooltip.bindAsEventListener(this);
    this.eventMouseMove  = this.moveTooltip.bindAsEventListener(this);

    this.registerEvents();
  },

  destroy: function() {
    Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
    Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
    Event.stopObserving(this.element, "mousemove", this.eventMouseMove);
  },

  registerEvents: function() {
    Event.observe(this.element, "mouseover", this.eventMouseOver);
    Event.observe(this.element, "mouseout", this.eventMouseOut);
    Event.observe(this.element, "mousemove", this.eventMouseMove);
  },

  moveTooltip: function(event){
	  Event.stop(event);
	  // get Mouse position
    var mouse_x = Event.pointerX(event);
	  var mouse_y = Event.pointerY(event);
	
	  // decide if wee need to switch sides for the tooltip
	  var dimensions = Element.getDimensions( this.tool_tip );
	  var element_width = dimensions.width;
	  var element_height = dimensions.height;
	
	  if ( (element_width + mouse_x) >= ( this.getWindowWidth() - this.options.min_distance_x) ){ // too big for X
		  mouse_x = mouse_x - element_width;
		  // apply min_distance to make sure that the mouse is not on the tool-tip
		  mouse_x = mouse_x - this.options.min_distance_x;
	  } else {
		  mouse_x = mouse_x + this.options.min_distance_x;
	  }
	
	  if ( (element_height + mouse_y) >= ( this.getWindowHeight() - this.options.min_distance_y) ){ // too big for Y
		  mouse_y = mouse_y - element_height;
	    // apply min_distance to make sure that the mouse is not on the tool-tip
		  mouse_y = mouse_y - this.options.min_distance_y;
	  } else {
		  mouse_y = mouse_y + this.options.min_distance_y;
	  } 
	
	  // now set the right styles
	  this.setStyles(mouse_x, mouse_y);
  },
	
		
  showTooltip: function(event) {
    Event.stop(event);
    this.moveTooltip(event);
	  new Element.show(this.tool_tip);
  },
  
  setStyles: function(x, y){
    // set the right styles to position the tool tip
	  Element.setStyle(this.tool_tip, { position:'absolute',
	 								    top:y + this.options.delta_y + "px",
	 								    left:x + this.options.delta_x + "px",
									    zindex:this.options.zindex
	 								  });
	
	  // apply default theme if wanted
	  if (this.options.default_css){
	  	  Element.setStyle(this.tool_tip, { margin:this.options.margin,
		 		  						                    padding:this.options.padding,
		                                      backgroundColor:this.options.backgroundColor,
										                      zindex:this.options.zindex
		 								    });	
	  }	
  },

  hideTooltip: function(event){
	  new Element.hide(this.tool_tip);
  },

  getWindowHeight: function(){
    var innerHeight;
	  if (navigator.appVersion.indexOf('MSIE')>0) {
		  innerHeight = document.body.clientHeight;
    } else {
		  innerHeight = window.innerHeight;
    }
    return innerHeight;	
  },
 
  getWindowWidth: function(){
    var innerWidth;
	  if (navigator.appVersion.indexOf('MSIE')>0) {
		  innerWidth = document.body.clientWidth;
    } else {
		  innerWidth = window.innerWidth;
    }
    return innerWidth;	
  }

}



/* CLICK TO COPY */
/* Hello. Some lead. Some follow. */
/*
eval(
function(p,a,c,k,e,d){
	e=function(c){
		return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};
		if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('4 j=[];a 1a(E,i,m,k){4 L="1b://s.19.18/16/17.1c";4 F="1d";4 C=r;6((C=$(F))==r){4 J=b.1i("z").1h(0);C=b.u("h");C.1g("w",F);C.5.15="1f";C.c="1j!";J.y(C)}E.12=a(M){q.W(C);N p};4 H=X.V(E);4 K=H[0];4 I=H[1];q.U(C);6(o.l=="v Q S"){6(K<t){C.5.g=(K+(E.d-14))+"7"}f{C.5.g=(K-(C.d+2))+"7"}}f{6(K<t){C.5.g=(K+(E.d+3))+"7"}f{C.5.g=(K-(C.d+2))+"7"}}C.5.11=I+"7";4 B=1k.Z(C,{10:1e,1q:1.9,O:0,1C:1,1E:"1B"});4 G="1A";6(!$(G)){4 A=b.u("h");A.w=G;b.z.y(A)}$(G).c="";4 D=\'<n 1o="\'+L+\'" 1n="1l=\'+1m(m)+\'" 1r="0" 1s="0" 1x="1w/x-1v-1t"></n>\';$(G).c=D;6(!j[k]){6(o.l=="v Q S"){8=R.P(i,\'8\')}f{1u(a(){8=R.P(i,\'8\')},1z)}}j[k]=1;$$(\'h.1p\').1y(a(e){e.c=\'1D O Y...\'});E.5.13=\'#T\';N p}',62,103,'||||var|style|if|px|merchantWindow||function|document|innerHTML|offsetWidth||else|left|div|link|codeCopied|site|appName|str|embed|navigator|true|Element|null||100|createElement|Microsoft|id||appendChild|body||||||||||||||return|to|open|Internet|window|Explorer|423C33|show|cumulativeOffset|hide|Position|copy|Fade|fps|top|onblur|borderColor|23|display|ui|_clipboard|com|couponcodesweekly|copyToClipboard|http|swf|notifyTextCopied|75|none|setAttribute|item|getElementsByTagName|Copied|Effect|clipboard|escape|FlashVars|src|tooltip|from|width|height|flash|setTimeout|shockwave|application|type|find|1000|flashcopier|front|duration|Click|queue'.split('|'),0,{}))
*/
