/* Retailers */

	var retailers = [ 	
				"online|riteaid.gif|http://www.riteaidonlinestore.com/search/search.asp?searchtype=1&trx=28198&trxp1=36952&ipp=20&srchtree=5&search=OcuFresh<sup>&reg;</sup>&Go.x=0&Go.y=0|Rite Aid",
				 "online|cvs.png|http://www.cvs.com/CVSApp/catalog/shop_product_detail.jsp?filterBy=&skuId=257039&productId=257039&navAction=jump&navCount=3|CVS/Pharmacy",
				 "find|kerrdrug.png|http://www.kerrdrug.com/store_locator|Kerr Drug",
				 "find|winndixie.png|http://www.winndixie.com/Store_Locations/Search.asp|Winn Dixie",
				 "find|ap.png|http://www.apfreshonline.com/pages_aboutUs_SL.asp|A&amp;P",
				 "find|foodcity.png|http://www.foodcity.com/food_city_interior_page/find_your_store/|Food City",
				 <!-- "online|aclens.png|http://www.aclens.com/Accessories/Brand/Types/Dry-Red-Eye-Treatments/6/232/Dry-Red-Eye-Treatments.html", -->
				 "online|amazon.png|http://www.amazon.com/OcuFresh<sup>&reg;</sup>-Eye-Wash-6-ea/dp/B00123G9PO/ref=sr_1_1?ie=UTF8&s=hpc&qid=1278496577&sr=1-1|Amazon",
				 "online|drugstore.png|http://www.drugstore.com/products/prod.asp?pid=94197&catid=47341&trx=PLST-0-SEARCH&trxp1=47341&trxp2=94197&trxp3=1&trxp4=0&btrx=BUY-PLST-0-SEARCH|Drugstore.com",
				  "find|meijer.png|http://www.meijer.com/custserv/store_locator.jsp|Meijer",
				  "find|walgreens.gif|http://www.walgreens.com/marketing/storelocator/find.jsp?_requestid=45823|Walgreens"
				 ];
	<!-- "kerrdrug.png|http://locator.kerrdrug.com/locator/store_locator.jsf" -->
	var cur;
	
	function getRandomRetailer() { 
		var toR,rand=cur;
		while(rand==cur) {rand=Math.floor(Math.random() * retailers.length); }
		cur = rand;
		return retailers[rand];
	}
	
	function displayRetailer(retailer) { 
		$('#rLogo').hide().prev().hide();
		$('#loader').show();
		$('#rLogo').html('');
		
		// If we display the link
		/*
		if(info[0]=='online') $('#rLogo').prev().html('purchase online at ');
		else 			  $('#rLogo').prev().html('purchase at ');
		*/
		/*
		var info = retailer.split('|'), lk=$('<span/>'), img = $('<img/>').attr('src','_img/retailers/'+info[1]);
		if(info[0]=='online') $('#rLogo').prev().html('purchase online at ');
		else 			  $('#rLogo').prev().html('purchase at ');
		*/
		
		var info = retailer.split('|'), lk = $('<a target="_blank"/>').attr('href',info[2]), img = $('<img/>').attr('src','_img/retailers/'+info[1]);

		img.appendTo(lk);
		lk.appendTo($('#rLogo'));
		
		$('#loader').fadeOut(300,function() {$('#rLogo').show();});
	}
	
	function getNextRetailer() {
		(cur!=retailers.length-1)?cur++:cur=0;
		displayRetailer(retailers[cur]);
		return false;
	}	
	
	function getListOfRetailersWithLinks() {
		var ul = $('<ul style="text-align: left; width: 150px; margin-left: 60px;"/>');	
		// If we display the link
		/*
		for(i=0;i<retailers.length;i++) {
				var info = retailers[i].split('|'), lk = info[2], name= info[3] ;
				$('<li><a href="'+lk+'" target="_blank">'+name+'</a></li>').appendTo(ul);
		}
		*/
		
		for(i=0;i<retailers.length;i++) {
				var info = retailers[i].split('|'), lk = info[2], name= info[3] ;
				$('<li>'+name+'</li>').appendTo(ul);
		}
		return ul;	
	}
	
/**
 * @author Alexander Farkas
 * v. 1.02
 * [animate background for menu aniùmation]
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);	
	
/* Menu Animation */
$(function() {

	$('#mntm a')
		.filter(function(){return !$(this).hasClass('cur')})
		.css( {backgroundPosition: "-20px 37px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-20px 144px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(40px 37px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-20px 37px"})
			}})
		});
})

// JQuery Cookie Plugin
jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

