/**
 * @author Laurynas Karvelis
 * @author "made.By" - www.by.lt
 * @date 2007-09-10
 */

// cookie support
eval(function(p,a,c,k,e,r){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--)r[e(c)]=k[c]||e(c);k=[function(e){return r[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}('s.5=D(a,b,c){4(m b!=\'E\'){c=c||{};4(b===p){b=\'\';c.3=-1}2 d=\'\';4(c.3&&(m c.3==\'n\'||c.3.q)){2 e;4(m c.3==\'n\'){e=B F();e.H(e.I()+(c.3*J*t*t*z))}r{e=c.3}d=\'; 3=\'+e.q()}2 f=c.7?\'; 7=\'+c.7:\'\';2 g=c.8?\'; 8=\'+c.8:\'\';2 h=c.o?\'; o\':\'\';6.5=[a,\'=\',C(b),d,f,g,h].G(\'\')}r{2 j=p;4(6.5&&6.5!=\'\'){2 k=6.5.A(\';\');y(2 i=0;i<k.9;i++){2 l=s.w(k[i]);4(l.u(0,a.9+1)==(a+\'=\')){j=v(l.u(a.9+1));x}}}K j}};',47,47,'||var|expires|if|cookie|document|path|domain|length|||||||||||||typeof|number|secure|null|toUTCString|else|jQuery|60|substring|decodeURIComponent|trim|break|for|1000|split|new|encodeURIComponent|function|undefined|Date|join|setTime|getTime|24|return'.split('|'),0,{}))

jQuery(document).ready(function() {
	jQuery('div#groups a').hover(
		function() {
			var id = jQuery('div.tip-shadow', jQuery(this).parent()).attr('id');
			showToolbar(id);
		},
		function() {
			hideToolbar();
		}
	);
	
	jQuery('form#medicsFrom').submit(function() {
		var url = jQuery(this).attr('action') + jQuery('form#medicsFrom #type').val() + 'city:' + jQuery('form#medicsFrom #city').val() + '/';
		window.location = url;
		return false;
	});

	if(typeof jQuery.fn.rating == 'function') {
		jQuery('form.rating').rating();
	}
	
	jQuery('div.ratingDesc, div.postComment, td.medic').hover(
		function() {
			jQuery(this).addClass('activeBlock');
		},
		function() {
			jQuery(this).removeClass('activeBlock');
		}
	);
	
	//	User rating
	jQuery('div[name=urate_1], div.[name=urate_2], div.[name=urate_3], div.[name=urate_4], div.[name=urate_5]').hover(
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			to = jQuery(this).attr('name').substring(6);
			_this = jQuery(this).parent('div');
			jQuery(_this).find(".rated").hide();
			for (i = 1; i <= to; i++){
				_this.find("div[name=urate_" + i + "]").css('background-position', '0 -26px');
			}
		},
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			jQuery(_this).find(".rated").show();
			_this = jQuery(this).parent('div');
			for (i = 1; i <= 5; i++){
				jQuery(_this).find("div[name=urate_" + i + "]").css('background-position', '0 0');
			}
		}
	);
	jQuery('div[name=urate_1], div.[name=urate_2], div.[name=urate_3], div.[name=urate_4], div.[name=urate_5]').click(function(){
		if (jQuery(this).hasClass('canrate') == false)
			return false;
		p = jQuery(this).parent('div');
		to = jQuery(this).attr('name').substring(6);
		navg = jQuery(p).attr('id').substring(9).replace(/-/, '/');
		jQuery(p).load('http://www.ledi.lt/lt/anketa/vertinti-anketa/' + navg + '/' + to);
	});
	
	//	Company catalog rating
	jQuery('div[name=crate_1], div.[name=crate_2], div.[name=crate_3], div.[name=crate_4], div.[name=crate_5]').hover(
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			to = jQuery(this).attr('name').substring(6);
			_this = jQuery(this).parent('div');
			jQuery(_this).find(".rated").hide();
			for (i = 1; i <= to; i++){
				_this.find("div[name=crate_" + i + "]").css('background-position', '0 -26px');
			}
		},
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			jQuery(_this).find(".rated").show();
			_this = jQuery(this).parent('div');
			for (i = 1; i <= 5; i++){
				jQuery(_this).find("div[name=crate_" + i + "]").css('background-position', '0 0');
			}
		}
	);
	jQuery('div[name=crate_1], div.[name=crate_2], div.[name=crate_3], div.[name=crate_4], div.[name=crate_5]').click(function(){
		if (jQuery(this).hasClass('canrate') == false)
			return false;
		to = jQuery(this).attr('name').substring(6);
		p = jQuery(this).parent('div');
		userId = jQuery(p).attr('id').substring(9);
		jQuery(p).load('http://www.ledi.lt/vote.php?id=' + userId + '&rate=' + to);
	});
	
	//	Gallery rating
	jQuery('div[name=rate_1], div.[name=rate_2], div.[name=rate_3], div.[name=rate_4], div.[name=rate_5]').hover(
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			to = jQuery(this).attr('name').substring(5);
			_this = jQuery(this).parent('div');
			jQuery(_this).find(".rated").hide();
			for (i = 1; i <= to; i++){
				_this.find("div[name=rate_" + i + "]").css('background-position', '0 -26px');
			}
		},
		function(){
			if (jQuery(this).hasClass('canrate') == false)
				return false;
			jQuery(_this).find(".rated").show();
			_this = jQuery(this).parent('div');
			for (i = 1; i <= 5; i++){
				jQuery(_this).find("div[name=rate_" + i + "]").css('background-position', '0 0');
			}
		}
	);
	jQuery('div[name=rate_1], div[name=rate_2], div[name=rate_3], div[name=rate_4], div[name=rate_5]').click(function(){
		if (jQuery(this).hasClass('canrate') == false)
			return false;
		p = jQuery(this).parent('div');
		to = jQuery(this).attr('name').substring(5);
		navg = jQuery(p).attr('id').substring(9).replace(/-/, '/');
		jQuery(p).load('http://www.ledi.lt/lt/anketa/vertinti/' + navg + '/' + to);
	});
	
	jQuery('.voting').click(function(){
		jQuery.getJSON(jQuery(this).attr('href') + '&ajax=true', function(data){
			if (data[0] != null && data[1] != null){
				table = jQuery('.votingTable');
				table.find('div:first').html('<span style="font-size: 22px; font-weight: bold; color: #981658; font-family: Trebuchet MS">'+data[0]+'</span>');
				table.find('div:last').html('<span style="font-size: 22px; font-weight: bold; color: #981658; font-family: Trebuchet MS">'+data[1]+'</span>');
			}
		});
		return false
	});
	
	//	Binding hover
	jQuery('.voting img').hover(function(){
		$(this).attr('src', 'http://www.ledi.lt/common/images/vote_on.png');
	},function(){
		$(this).attr('src', 'http://www.ledi.lt/common/images/vote.png');
	});
});


function getMouseXY(e) {
	var e = (!e) ? window.event : e;
	var posScroll = 0;
	
	posX = 0;
	posY = 0;
	
	if (e.pageX || e.pageY) {
		posX = e.pageX;
		posY = e.pageY;
		posScroll = document.documentElement.scrollTop;
	} else if (e.clientX || e.clientY) {
		if (document.body.scrollLeft || document.body.scrollTop) {
			posX = e.clientX + document.body.scrollLeft;
			posY = e.clientY + document.body.scrollTop;
			posScroll = document.body.scrollTop;
		} else {
			posX = e.clientX + document.documentElement.scrollLeft;
			posY = e.clientY + document.documentElement.scrollTop;
			posScroll = document.documentElement.scrollTop;
		}
	}
	
	updateToolbar();
}

function updateToolbar() {	
	if(wmtt != null){	
		jQuery(wmtt).css('left', (posX + 10) + "px");
		jQuery(wmtt).css('top', (posY + 10) + "px");
	}
}

function showToolbar(id){
	wmtt = jQuery('div#' + id);
	updateToolbar();
	
	jQuery(wmtt).show();
}

function hideToolbar(){
	jQuery(wmtt).hide();
	wmtt = null;
}

document.onmousemove = getMouseXY;
wmtt = null;
