/*
*
* jQuery listmenu plugin
* Copyright (c) 2009 iHwy, Inc.
* Author: Jack Killpatrick
*
* Version 1.1 (08/09/2009)
* Requires jQuery 1.3.2 or jquery 1.2.6
*
* Visit http://www.ihwy.com/labs/jquery-listmenu-plugin.aspx for more information.
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
*/

(function($) {
	$.fn.listmenu = function(options) {
		var opts = $.extend({}, $.fn.listmenu.defaults, options); var alph = ['_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-']; return this.each(function() {
			var $wrapper, list, $list, $letters, letters = {}, $letterCount, id, $menu, colOpts = $.extend({}, $.fn.listmenu.defaults.cols, opts.cols), onNav = false, onMenu = false, currentLetter = ''; id = this.id; $list = $(this); function init() { $list.css('visibility', 'hidden'); setTimeout(function() { $list.before(createWrapperHtml()); $wrapper = $('#' + id + '-menu'); $wrapper.append(createLettersHtml());createLink(opts.categorialink); $letters = $('.lm-letters', $wrapper).slice(0, 1); if (opts.showCounts) $letterCount = $('.lm-letter-count', $wrapper).slice(0, 1); $wrapper.append(createMenuHtml()); $menu = $('.lm-menu', $wrapper); populateMenu(); if (opts.flagDisabled) addDisabledClass(); bindHandlers(); if (!opts.includeNums) $('._', $letters).remove(); if (!opts.includeOther) $('.-', $letters).remove(); $(':last', $letters).addClass('lm-last'); $wrapper.show(); }, 50); }
			function setLetterCountTop() { $letterCount.css({ top: $('.a', $letters).slice(0, 1).offset({ margin: false, border: true }).top - $letterCount.outerHeight({ margin: true }) }); }
			function addDisabledClass() { for (var i = 0; i < alph.length; i++) { if (letters[alph[i]] == undefined) $('.' + alph[i], $letters).addClass('lm-disabled'); } }
			function populateMenu() {
				var gutter = colOpts.gutter, cols = colOpts.count, menuWidth, colWidth; if (opts.menuWidth) menuWidth = opts.menuWidth; else menuWidth = $('.lm-letters', $wrapper).width() - ($menu.outerWidth() - $menu.width()); colWidth = (cols == 1) ? menuWidth : Math.floor((menuWidth - (gutter * (cols - 1))) / cols); $menu.width(menuWidth); $list.width(colWidth); var letter, outerHeight; $list.children().each(function() {
					str = $(this).text().replace(/\s+/g, ''); if (str != '') { firstChar = str.slice(0, 1).toLowerCase(); if (/\W/.test(firstChar)) firstChar = '-'; if (!isNaN(firstChar)) firstChar = '_'; }
					outerHeight = $(this).outerHeight(); if (letters[firstChar] == undefined) letters[firstChar] = { totHeight: 0, count: 0, colHeight: 0, hasMenu: false }; letter = letters[firstChar]; letter.totHeight += outerHeight; letter.count++; $.data($(this)[0], id, { firstChar: firstChar, height: outerHeight });
				}); $.each(letters, function() { this.colHeight = (this.count > 1) ? Math.ceil(this.totHeight / cols) : this.totHeight; }); var $this, data, iHeight, iLetter, cols = {}, c; var tagName = $list[0].tagName.toLowerCase(); $list.children().each(function() {
					$this = $(this); data = $.data($this.get(0), id); iLetter = data.firstChar; iHeight = data.height; if (!letters[l = iLetter].hasMenu) { $menu.append('<div class="lm-submenu ' + iLetter + '" style="display:none;"></div>'); letters[iLetter].hasMenu = true; }
					if (cols[iLetter] == undefined) cols[iLetter] = { height: 0, colNum: 0, itemCount: 0, $colRoot: null }; c = cols[iLetter]; c.itemCount++; if (c.height == 0) { c.colNum++; $('.lm-submenu.' + iLetter, $menu).append('<div class="lm-col c' + c.colNum + '"><' + tagName + ((tagName == 'ol') ? ' start="' + c.itemCount + '"' : '') + ' id="lm-' + id + '-' + iLetter + '-' + c.colNum + '" class="lm-col-root"></' + tagName + '></div>'); }
					$('#lm-' + id + '-' + iLetter + '-' + c.colNum).append($(this)); c.height += iHeight; if (c.height >= letters[iLetter].colHeight) c.height = 0;
				}); $.each(letters, function(idx) { if (this.hasMenu) { $('.lm-submenu.' + idx + ' .lm-col', $menu).css({ 'width': colWidth }); $('.lm-submenu.' + idx + ' .lm-col:not(:last)', $menu).css({ 'marginRight': gutter }); } }); $menu.append('<div class="lm-no-match" style="display:none">' + opts.noMatchText + '</div>'); $list.remove();
			}
			function getLetterCount(el) { var letter = letters[$(el).attr('class').split(' ')[0]]; return (letter != undefined) ? letter.count : 0; }
			function hideCurrentSubmenu() { if (currentLetter != '') $('.lm-submenu.' + currentLetter, $menu).hide(); $('.lm-no-match', $menu).hide(); }
			function bindHandlers() {
				if (opts.showCounts) { $wrapper.mouseover(function() { setLetterCountTop(); }); }
				$('a', $letters).click(function() { $(this).blur(); return false; }); $letters.hover(function() { onNav = true; }, function() { onNav = false; setTimeout(function() { if (!onMenu) { $('a.lm-selected', $letters).removeClass('lm-selected'); $('.lm-menu', $wrapper).hide(); hideCurrentSubmenu(); currentLetter = ''; } }, 10); }); $('a', $letters).mouseover(function() {
					var count = getLetterCount(this); var $this = $(this); if (opts.showCounts) { var left = $this.position().left; var width = $this.outerWidth({ margin: true }); if (opts.showCounts) $letterCount.css({ left: left, width: width + 'px' }).text(count).show(); }
					var newLetter = $this.attr('class').split(' ')[0]; if (newLetter != currentLetter) {
						if (currentLetter != '') { hideCurrentSubmenu(); $('a.lm-selected', $letters).removeClass('lm-selected'); }
						$this.addClass('lm-selected'); if (count > 0) $('.lm-submenu.' + newLetter, $wrapper).show(); else $('.lm-no-match', $wrapper).show(); if (currentLetter == '') $('.lm-menu', $wrapper).show(); currentLetter = newLetter;
					}
				}); $('a', $letters).mouseout(function() { if (opts.showCounts) $letterCount.hide(); }); $menu.hover(function() { onMenu = true; }, function() { onMenu = false; setTimeout(function() { if (!onNav) { $('a.lm-selected', $letters).removeClass('lm-selected'); $('.lm-menu', $wrapper).hide(); hideCurrentSubmenu(); currentLetter = ''; } }, 10); }); if (opts.onClick != null) { $menu.click(function(e) { var $target = $(e.target); opts.onClick($target); return false; }); }
			}
			function createLettersHtml() {
				var html = []; for (var i = 1; i < alph.length; i++) { if (html.length == 0) html.push('<a class="_" href="#">0-9</a>'); html.push('<a class="' + alph[i] + '" href="#">' + ((alph[i] == '-') ? '...' : alph[i].toUpperCase()) + '</a>'); }
				return '<div class="lm-letters">' + html.join('') + '</div>' + ((opts.showCounts) ? '<div class="lm-letter-count" style="display:none; position:absolute; top:0; left:0; width:20px;">0</div>' : '');
			}
			function createMenuHtml() { return '<div class="lm-menu"></div>'; }
			function createWrapperHtml() { return '<div id="' + id + '-menu" class="lm-wrapper"></div>'; }
      function createLink(categorialink){
        $.each($('div.lm-letters a'),function(k,v){
            $(this).bind('click', function() {
                $(this).removeClass("lm-first lm-selected lm-last lm-disabled");
                window.location = categorialink+$(this).attr('class');
            });
        });
      }
			init();
		});
	}; $.fn.listmenu.defaults = { includeNums: true, includeOther: false, flagDisabled: true, noMatchText: 'No matching entries', showCounts: true, menuWidth: null, cols: { count: 4, gutter: 40 }, onClick: null, categorialink:'/' };
})(jQuery);

/*************
* Touch dialog box is exclusively available at CodeCanyon.
* Developed by Pixelatom
* If you want to use it in your website
* buy it at http://codecanyon.net/item/touch-dialog-box/116031
*/
(function($){
	$.fn.touchDialog = function(linkElement, options) {

	var defaults = {
		elementId: 'containerTouchDialog',
		background: '#444444',
		fontColor: '#FFF',
		shadowColor: '#222',
		effectShow: 'default',
		fontFamily: 'Arial, Helvetica, sans-serif',
		zIndex: 100,
		colorGap: 100
	};

	var options = $.extend(defaults, options);



	function getNewColor(color,sign){
		var colorInt = parseInt(color, 16);
		if(sign == 'plus') colorInt = colorInt + parseInt(options.colorGap);
		else colorInt = colorInt - parseInt(options.colorGap);
		if(colorInt > 255) colorInt = 255;
		if(colorInt < 0) colorInt = 0;
		colorInt = colorInt.toString(16);
		if(colorInt.length < 2)colorInt = "0" + colorInt;
		return colorInt;
	}

	/*Color calculus*/

	var baseColor = options.background.replace('#','');
	if(baseColor.length != 3 && baseColor.length != 6) baseColor = '444';
	if(baseColor.length == 3){
		var redColor = baseColor.substr(0,1);
		var greenColor = baseColor.substr(1,1);
		var blueColor = baseColor.substr(2,1);
		redColor = ''+redColor+redColor;
		greenColor = ''+greenColor+greenColor;
		blueColor = ''+blueColor+blueColor;
	}
	else{
		var redColor = baseColor.substr(0,2);
		var greenColor = baseColor.substr(2,2);
		var blueColor = baseColor.substr(4,2);
	}

	var shineCol = '#'+getNewColor(redColor,'plus')+getNewColor(greenColor,'plus')+getNewColor(blueColor,'plus');
	var shadowCol = '#'+getNewColor(redColor,'minus')+getNewColor(greenColor,'minus')+getNewColor(blueColor,'minus');

	/*End color calculus*/

	var caller = $(this);
	var obj = $(linkElement);
	$(linkElement).css('display','none');
	var body = obj.html();
	var optionTexts = [];
	$(body).each(function() { if($.trim($(this).html()) != '') optionTexts.push($(this).html()) });
	var screenRatio = 320;

	/*Future autosize*/

	var heightDialog = Math.round(0.13 * screenRatio);
	var heightFont = Math.round(0.04 * screenRatio);
	var heightArrow = Math.round(0.0375 * screenRatio);
	var paddingFont = Math.round((heightDialog - heightFont)/2);
	var halfPadding = Math.round(paddingFont / 2);
	var linksString = '';
	var thisSameEffect = '';

	/*End future autosize*/

	/*Getting UL contents*/
	for(var i in optionTexts){
		linksString = linksString+optionTexts[i];
	}

	$.fn.touchDialog.updateOrientationIPhoneOnly = function(){
		$('#'+options.elementId).css('display','none');
	};

		return this.each(function() {

			/*Click event*/
			caller.click(function(event){
				/*If widget exists, remove it*/
				$('#'+options.elementId).remove();

				/*Draw widget*/
				$('body').append('<div id="'+options.elementId+'">\
				                      <div>\
									      '+linksString+'\
										  <div>\
										  </div>\
								      </div>\
									  <div>\
									      <span></span><span></span>\
									  </div>\
								  </div>');

				var dialogContainer = $('#'+options.elementId);
				var linksContainer = $('#'+options.elementId+' div').first();
				var linksContainerElements = $('#'+options.elementId+' a');
				var arrowBox = $('#'+options.elementId+' div').last();
				var arrowElement = $('#'+options.elementId+' span');

				dialogContainer.css({
					'position': 'absolute',
					'min-height' : heightDialog+'px',
					'padding' : halfPadding+'px',
					'overflow' : 'hidden'
				});

				linksContainer.css({
					'border-bottom' : '1px solid #000',
					'border-right' : '1px solid '+shadowCol,
					'border-left' : '1px solid '+shadowCol,
					'background-color' : shadowCol,
					'z-index' : (options.zIndex+1),
					'border-radius' : '0.5em',
					'-moz-border-radius' : '0.5em',
					'-webkit-border-radius' : '0.5em',
					'box-shadow' : '0px 2px 3px '+options.shadowColor,
					'-moz-box-shadow' : '0px 2px 3px '+options.shadowColor,
					'-webkit-box-shadow' : '0px 2px 3px '+options.shadowColor,
					'font-size' : heightFont+'px',
					'min-height' : heightDialog+'px',
					'font-weight': 'bold',
					'padding' : '0px 0.5em 0px 0.5em',
					'position' : 'relative',
					'overflow' : 'hidden'
				});

				linksContainerElements.css({
					'display' : 'block',
					'position' : 'relative',
					'float' : 'left',
					'text-shadow' : '0 2px 2px rgba(0, 0, 0, 0.5)',
					'margin-top' : '2px',
					'text-decoration' : 'none',
					'color' : options.fontColor,
					'font-family' : options.fontFamily,
					'padding' : (paddingFont-1)+'px '+paddingFont+'px '+Math.round(paddingFont*.8)+'px '+paddingFont+'px',
					'z-index' : options.zIndex+4,
					'border-left': '1px solid '+options.background,
					'whiteSpace' : 'nowrap',
					'border-right': '1px solid '+shadowCol
				});

				if(!navigator.userAgent.match(/Opergfdgdfa/)){
					linksContainerElements.hover( function(){
							if(navigator.userAgent.match(/Chrome/)){
								$(this).css({
									'background-color' : '#'+baseColor,
									'background' : '-webkit-gradient(linear, left top, left bottom, from('+shadowCol+'), to('+options.background+'))'
								})
							}
							else if(navigator.userAgent.match(/Firefox/)){
								$(this).css({
									'background-color' : '#'+baseColor,
									'background': '-moz-linear-gradient(top, '+shadowCol+', '+options.background+')'
								});
							}
							else if(navigator.userAgent.match(/MSIE/)){
								$(this).css({
									'background-color' : '#'+baseColor,
									'filter' : 'progid:DXImageTransform.Microsoft.gradient(startColorstr="'+shadowCol+'", endColorstr="'+options.background+'")'
								})
							}
							else{
								$(this).css({
									'background-color' : shadowCol
								})
							}
						},
						function(){
							$(this).css({
								'background' : 'transparent',
								'filter' : 'none'
							});
					});
				}

				arrowBox.css({
					'z-index' : (options.zIndex),
					'position' : 'absolute'
				});

				arrowElement.css({
					'float': 'left',
					'display': 'block',
					'height' : halfPadding+'px',
					'width' : halfPadding+'px',
					'border-bottom' : halfPadding+'px solid transparent',
					'border-top' : halfPadding+'px solid transparent',
					'margin' : '0px',
					'z-index' : (options.zIndex+1),
					'position' : 'relative'
				});

				if(!navigator.userAgent.match(/Ofdsfsfdsapera/)){
					linksContainerElements.first().css({
						'-moz-border-radius-topleft' : '0.8em',
						'-moz-border-radius-bottomleft' : '0.8em',
						'-webkit-border-top-left-radius' : '0.8em',
						'-webkit-border-bottom-left-radius' : '0.8em',
						'border-top-left-radius' : '0.8em',
						'border-bottom-left-radius' : '0.8em',
						'border-left':'0',
						'margin-left' : '-10px',
						'padding-left' : (paddingFont+10)+'px'
					});
					linksContainerElements.last().css({
						'-moz-border-radius-topright' : '0.8em',
						'-moz-border-radius-bottomright' : '0.8em',
						'-webkit-border-top-right-radius' : '0.8em',
						'-webkit-border-bottom-right-radius' : '0.8em',
						'border-top-right-radius' : '0.8em',
						'border-bottom-right-radius' : '0.8em',
						'border-right':'0',
						'margin-right' : '-10px',
						'padding-right' : (paddingFont+10)+'px'
					});
				}
				else{
					linksContainerElements.first().css({
						'border-left':'0'
					});
					linksContainerElements.last().css({
						'border-right':'0'
					});
				}

				/*Getting widget width*/
				var totalWidth = 0;
				linksContainerElements.each(function() { totalWidth = totalWidth + $(this).width() + (2*paddingFont) + 2; });
				linksContainer.css('maxWidth',totalWidth);

				$('#'+options.elementId+' div>div').first().css({
					'margin' : '1px -0.5em 0px -0.5em',
					'border-top' : '1px solid '+shineCol,
					'border-right' : '1px solid '+options.background,
					'border-left' : '1px solid '+options.background,
					'z-index' : (options.zIndex+3),
					'top': '0px',
					'left' : '5px',
					'height' : '50%',
					'background-color' : options.background,
					'min-height' : Math.round(heightDialog/2)+'px',
					'border-radius' : '0.5em',
					'-moz-border-radius' : '0.5em',
					'-webkit-border-radius' : '0.5em',
					'width' : totalWidth+10,
					'position' : 'absolute'
				});

				dialogContainer.css('left','-'+(totalWidth+(paddingFont*2))+'px');

				/*Getting widget positions*/
				var leftMove = (totalWidth+(paddingFont*2))*(-1);
				var leftPos = pointArrow = event.pageX-20;
				if((totalWidth+(paddingFont)) < leftPos){
					if(leftPos > ($(window).width() - totalWidth+(paddingFont))) leftPos = (leftPos-(totalWidth));
					else leftPos = (leftPos-(totalWidth-(paddingFont*2)));
					pointArrow = totalWidth-10;
				}
				else leftPos = 10;

				/*Fixing point arrow position*/
				if(pointArrow < 5) pointArrow = 5;
				if(pointArrow > totalWidth-10) pointArrow = totalWidth-10;

				/*Drawing point arrow*/
				if(event.pageY <= (heightDialog + (paddingFont*2))){
					var cssDataArrow = {
						'left' : pointArrow+'px',
						'top' : '0px'
					}
					dialogContainer.css('top',(event.pageY)+'px');
					$('#'+options.elementId+' span').first().css('borderRight',(Math.round(paddingFont/2))+'px solid '+options.background);
					$('#'+options.elementId+' span').last().css('borderLeft',(Math.round(paddingFont/2))+'px solid '+options.background);
				}
				else{
					var cssDataArrow = {
						'left' : pointArrow+'px',
						'bottom' : '0px'
					}
					dialogContainer.css('top',(event.pageY-(heightDialog+paddingFont))+'px');
					$('#'+options.elementId+' span').first().css('borderRight',(Math.round(paddingFont/2))+'px solid '+shadowCol);
					$('#'+options.elementId+' span').last().css('borderLeft',(Math.round(paddingFont/2))+'px solid '+shadowCol);
				}
				arrowBox.css(cssDataArrow);

				/*Only 2 effects available for now*/
				if(options.effectShow == 'fade'){
					dialogContainer.css({
						'display' : 'none',
						'left' : leftPos+'px'
					});
					/*Internet Explorer has problems with the fade*/
					if(navigator.userAgent.match(/MSIE/)) dialogContainer.css('display','block');
					else dialogContainer.fadeIn('fast');
				}
				else if(options.effectShow == 'none'){
					dialogContainer.css({'display':'block','left':leftPos+'px'});
				}
				else{
					dialogContainer.css('display','block').animate({left:(leftPos+20)}, 200).animate({left:(leftPos)}, 200);

				}
				thisSameEffect = options.effectShow;

				/*Stop or you're going to kill yourself*/
				event.stopPropagation();

				/*Remove if window resize (works for Android's screen rotation detection)*/
				$(window).resize(function() {
					dialogContainer.css('left',leftMove+'px');
					return false;
				});

			});

			/*Kill widget if somewhere else is clicked. does not work well in Mobile Safari*/
			$(document).not(caller).click(function(event){
				var totalWidth = 0;
				$('#'+options.elementId+' a').each(function() { totalWidth = totalWidth + $(this).width() + (2*paddingFont); });
				var leftMove = (totalWidth+(paddingFont*2))*(-1);

				$('#'+options.elementId).css('left',leftMove+'px');
			});
		});
	};
})(jQuery);

var novaBusca = function(){
	window.location = '/farmacia-medicamento-comprar-procurar/'+$('input[name=q]').val()+'';
}
