// JavaScript Document

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

$(document).ready(function(){

jQuery.preLoadImages("/images/b_buts/bbc1o.png", "/images/b_buts/bbc2o.png","/images/b_buts/bbc3o.png","/images/b_buts/bbc4o.png","/images/b_buts/bbc5o.png");

	$('a.email-protector').each(function(){
		var a = $(this).text();
		$(this).attr('href','mailto:' + a);
		})

	$('a.roll-over').hover(function(){
			var src = $(this).find('img').attr('src')
			if(src.substr(src.length - 5,1)!='o')
				{
				$(this).find('img').attr('orig',src);
				$(this).find('img').attr('src',src.substr(0,src.length - 4)+'o'+src.substr(src.length - 4,4));
				}
		},function(){
			if(!$(this).hasClass('active'))$(this).find('img').attr('src',$(this).find('img').attr('orig'));
		});
	
	$('a.roll-over.active').each(function(){
			var src = $(this).find('img').attr('src')
			$(this).find('img').attr('orig',src);
			$(this).find('img').attr('src',src.substr(0,src.length - 4)+'o'+src.substr(src.length - 4,4));
		});
	
	$('.stripes tr[class!=thead]:odd').addClass('row');
	
	$('.stripes tr[class!=thead]').hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});

if(jQuery.url != undefined)
{
	var url = jQuery.url.attr("path");
$('.sidebar a[href='+url+']').addClass('active');
if (url.match(/lansete/im)) $('#topmenu a[href=/lansete]').addClass('active');
if (url.match(/blancuri/im)) $('#topmenu a[href=/blancuri]').addClass('active');
if (url.match(/materiale/im)) $('#topmenu a[href=/materiale]').addClass('active');
if (url.match(/distribuitori/im)) $('#topmenu a[href=/distribuitori]').addClass('active');
if (url.match(/contact/im)) $('#topmenu a[href=/contact]').addClass('active');
}

//============================================================================

$('#breadcrumb a').hover(function(){
		if($(this).prev().size()>0)
			$(this).prev().addClass('h1');
		else
			$(this).parent().parent().parent().addClass('h1');
	},function(){
		if($(this).prev().size()>0)
			$(this).prev().removeClass('h1');
		else
			$(this).parent().parent().parent().removeClass('h1');
	});

//============================================================================

$.get('/html/produse--random.html', function(data) {
		var pb = $('.pbox',data).random($('.random').attr('title'));
		$('.random').attr('title','');
		$('.random').html(pb);
		});

//============================================================================

if($('#harta_romania').size()>0)
{
$.fn.maphilight.defaults = {
	fill: true,
	fillColor: '000000',
	fillOpacity: 0.4,
	stroke: false,
	strokeColor: 'ff0000',
	strokeOpacity: 1,
	strokeWidth: 1,
	fade: true,
	alwaysOn: false
	}

$('#harta_romania').maphilight();

$('.imagemaps').bind("mouseover",function(){
	$('#tip').show();
	$('#tip .text').text($(this).attr('alt'));
	over_map = 1;
	clearTimeout(ts_timeout);
	});

$('.imagemaps').bind("mouseout",function(){
	ts_timeout = setTimeout(ts_hide,100);
	});

function ts_hide(){
	$('#tip').hide();
	}

$('#tip').hide();

var oy = $('#harta_romania').offset().top;
var ox = $('#harta_romania').offset().left;


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)

var tempX = 0;
var tempY = 0;
/*
function mouseCoords(ev){
	ev = (!ev && window.event)?window.event:ev;
	if(($.browser.msie))
		{
		if((ev.clientX!=null)&&(ev.clientY!=null))
		return {x:ev.clientX,y:ev.clientY};
		}
	else
		{
		if((ev.pageX!=null)&&(ev.pageY!=null))
			{
			//console.log(ev.pageX,ev.pageY);
			return {x:ev.pageX, y:ev.pageY};
			}
		}
	}
*/
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
	tempX = event.clientX + document.body.scrollLeft;
	tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
	tempX = e.pageX;
	tempY = e.pageY;
	}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  
	$('#tip').css({'top' : tempY-5-oy+115 + 'px', 'left':tempX+50-ox + 'px'});
	/*
	document.Show.MouseX.value = tempX;
	document.Show.MouseY.value = tempY;
	*/
	return true;
	}

document.onmousemove = getMouseXY;
/*
document.onmousemove = function(e){
	var p = mouseCoords(e);
	mouseX = p.x;
	mouseY = p.y;
	if(over_map)
		{
		$('#tip').css({'top' : mouseY-5 + 'px', 'left':mouseX+20 + 'px'});
		}
	};
*/

}
});



var ox,oy = 0;
var over_map = 0;
var ts_timeout = null;
