var c= Array("#asia","#meast","#europe","#africa","#lamerica","#america");
i1 =new Image();
i2 =new Image();
i3 =new Image();
i4 =new Image();
i5 =new Image();
i6 =new Image();
i1.src="images/maps/africa.jpg";
i2.src="images/maps/america.jpg";
i3.src="images/maps/lamerica.jpg";
i4.src="images/maps/meast.jpg";
i5.src="images/maps/asia.jpg";
i6.src="images/maps/europe.jpg";
function IsIE8Browser() {
    var rv = -1;
    var ua = navigator.userAgent;
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null) {
        rv = parseFloat(RegExp.$1);
    }
    return (rv == 4);
}
$(document).ready(function()
{
	x=0;
	if(IsIE8Browser()){
		x=1;
		$('#countries li ul li a').attr('style','position:relative; top:-1px;');
	}
   $('area').each(function()
   {
	switch (this.id){
			case'america':
				tipH="North America";
				$(this).bind('mouseover',function(){						  
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:44px;left:-212px');
				$("#map_hover img").fadeIn();
				});
			break;
			case'lamerica':
				tipH="Latin America";
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:197px;left:'+(-233-x)+'px');
				$("#map_hover img").fadeIn();
				});
			break;
			case'meast':
				tipH="Midle East";
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:174px;left:'+(68-x)+'px');
				$("#map_hover img").fadeIn();
				});
			break;
			case'europe':
				tipH="Europe";
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:72px;left:30px');
				$("#map_hover img").fadeIn();
				});
			break;
			case'asia':
				tipH="Asia";
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:148px;left:'+(179-x)+'px');
				$("#map_hover img").fadeIn();
				});
			break;
			case'africa':
				tipH="Africa";
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.id+'.jpg');
				$("#map_hover img").attr('style','top:190px;left:'+(13-x)+'px');
				$("#map_hover img").fadeIn();
				});
			break;
		}
     $(this).qtip(
      {
		target: 'mouse',
        content:{prerender:true,text:cont=$('#'+this.id+'tip').html(), title:{text:tipH}},
        position: { target: 'mouse',adjust: { mouse: false , x: 13, y: 0 }},
 		show:{ delay: 0,effect: {type:'slide',length: 100 } },
        hide:{effect: {type:'slide',length: 100 },fixed: true},
		//api:{onHide:function(){$("#map_hover img").hide();}},
        style: { 
			  width:{min: 150,max:240},
			  title: {color: '#ec1b24',background: '#FFFFFF',fontSize:11,paddingLeft:17,paddingBottom:10},
			  paddingLeft: 17,
			  paddingBottom:0,
			  paddingTop:0,
			  background: '#FFFFFF',
			  color: 'black',
			  textAlign: 'left',
			  border: {width: 3,radius: 3,color: '#b1b1b1'},
			  tip: 'leftTop'
			  }
      });
   })
   
   $('ul#countries li').each(function(){			
		switch (this.className){
			case'america':
				$(this).bind('mouseover',function(){	
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:44px;left:-212px');
				$("#map_hover img").show();
				});
			break;
			case'lamerica':
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:197px;left:'+(-233-x)+'px');
				$("#map_hover img").show();
				});
			break;
			case'meast':
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:174px;left:'+(68-x)+'px');
				$("#map_hover img").show();
				});
			break;
			case'europe':
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:72px;left:30px');
				$("#map_hover img").show();
				});
			break;
			case'asia':
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:148px;left:'+(179-x)+'px');
				$("#map_hover img").show();
				});
			break;
			case'africa':
				$(this).bind('mouseover',function(){
				$("#map_hover img").hide();
				$("#map_hover img").attr('style','');
				$("#map_hover img").attr('src','images/maps/'+this.className+'.jpg');
				$("#map_hover img").attr('style','top:190px;left:'+(13-x)+'px');
				$("#map_hover img").show();
				});
			break;
		}
	});		

   $('li a').each(function(){			
	$(this).bind('click',function(){
		if($('#storec').attr('checked')==true){
			$("input#loc").val(escape(this.className)); 
			$("#setlocation").submit();
			return false; // might need to check for dblclick
			}
		})					
	});
   $('#tips').remove();
});

// make text unselectable to avoid flashing cursor over image maps & div
var Unselectable = {
	enable : function(e) {
		var e = e ? e : window.event;
		if (e.button != 1) {
			if (e.target) {
				var targer = e.target;
			} else if (e.srcElement) {
				var targer = e.srcElement;
			}
			var targetTag = targer.tagName.toLowerCase();
			if ((targetTag != "input") && (targetTag != "textarea")) {
				return false;
			}
		}
	},
	disable : function () {
		return true;
	}
}
 
if (typeof(document.onselectstart) != "undefined") {
	document.onselectstart = Unselectable.enable;
} else {
	document.onmousedown = Unselectable.enable;
	document.onmouseup = Unselectable.disable;
}