jQuery(document).ready(function(){

  jQuery('a[rel*=lightbox]').lightBox();

  // setup fancy tooltips
  jQuery('a.load-local').cluetip({
    local:true,
    cursor: 'pointer',
    sticky: true,
    closePosition: 'title',
    closeText: '<img src="/stat/cross.png" alt="close" />',
    showTitle: false,
    activation: 'click',
    width: 200
  });

  jQuery('#mapcontainer').Accordion({ 
    active: '.selected', 
    header: 'span.head' 
  });

  jQuery('a.lightbox').lightBox({
		imageLoading:			'/images/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'/images/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'/images/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:		'/images/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'/images/lightbox/lightbox-blank.gif'			// (string) Path and the name of a blank image (one pixel)
  });

  jQuery('.jumpMenu').change(function(){
    url = this.options[this.selectedIndex].value;
    if(url != '') window.location = url;
  });

  // Give a link a class name like "popup size_440x380" and it'll open in a popup with those dimensions
  
  jQuery('a.popup').click(function(){
    dimensions = this.className.split('_')[1].split('x');
    width = dimensions[0];height = dimensions[1];
    x = Math.round((screen.width/2) - (width/2));
    y = Math.round((screen.height/2) - (height/2));
    features = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x;
    window.open(this.href, 'popup', features);
    return false;
  });


  // Track Google External Downloads
//	Javascript to tag file downloads and external links in Google Analytics
//	To use, place reference to this file should be placed at the bottom of all pages, 
//	just above the Google Analytics tracking code.
//	All outbound links and links to non-html files should now be automatically tracked.
//
//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//	Created by: 	Colm McBarron, colm.mcbarron@iqcontent.com
//	Last updated: 	12-Feb-2006
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//

var hrefs = document.getElementsByTagName("a");
var link_path = "";
for (var l = 0; l < hrefs.length; l++) {
		try {
			var link_path = hrefs[l].pathname;
			if (location.host == hrefs[l].hostname) {
				if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
					addtrackerlistener(hrefs[l]);
				}
			} else {
				addtrackerlistener(hrefs[l]);
			}
		}
		catch(err) { }
}


function addtrackerlistener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackfiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackfiles);
	}
}

function trackfiles(array_element) {
	file_path = "";
	if (location.host != this.hostname) {
		file_path = "/exlinks/" + ((array_element.srcElement) ? "/" + array_element.srcElement.hostname : this.hostname);
	}
	file_path = file_path + ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname);
	urchinTracker(file_path);
}

});


function track(event_type, id){
  jQuery.post('/track', {event_type: 'visit_retailer', id: id});
}