
var cur_page=0;

function get_page(pageid)
{
	var len=page_list.length;
	for(i=0;i < len;i++)
	{
		if(page_list[i][0] == pageid)
		{
			$('#nesan_img').css({display:''});
			$('#nesan_img').attr('src','uploads/images/'+page_list[i][1]);
			$('#nesan_img_map').empty();
			$('#nesan_img_map').css({backgroundImage : 'url(images/loader.gif)',backgroundRepeat:'no-repeat', backgroundPosition:'center', backgroundColor:'#FFFFFF' });
						
			$("#right_slid img[rel='"+ cur_page +"']").removeClass('border');
			cur_page = i;
			$("#right_slid img[rel='"+ cur_page +"']").addClass('border');
		}
	}
}

function nextPage()
{
	var len=page_list.length;

	if(cur_page<len-1)
	{
		$("#right_slid img[rel='"+ cur_page +"']").removeClass('border');
		cur_page++;
		$("#right_slid img[rel='"+ cur_page +"']").addClass('border');
		
		$('#nesan_img').css({display:''});
		$('#nesan_img').attr('src','uploads/images/'+page_list[cur_page][1]);
		$('#nesan_img_map').empty();
			$('#nesan_img_map').css({backgroundImage : 'url(images/loader.gif)',backgroundRepeat:'no-repeat', backgroundPosition:'center', backgroundColor:'#FFFFFF' });
	}
}

function previuousPage()
{
	if(cur_page>0)
	{
		$("#right_slid img[rel='"+ cur_page +"']").removeClass('border');
		cur_page--;
		$("#right_slid img[rel='"+ cur_page +"']").addClass('border');
		$('#nesan_img').css({display:''});
		$('#nesan_img').attr('src','uploads/images/'+page_list[cur_page][1]);
		$('#nesan_img_map').empty();
			$('#nesan_img_map').css({backgroundImage : 'url(images/loader.gif)',backgroundRepeat:'no-repeat', backgroundPosition:'center', backgroundColor:'#FFFFFF' });
	}
}

function load_map()
{
	
	if(page_list.length >0)
	pageid = page_list[cur_page][0];
	else
	return;	
	
	pos = $('#nesan_img').position();
	$('#nesan_img_map').removeClass('loader');
	$('#nesan_img_map').css({left:pos.left,top:pos.top,width:$('#nesan_img').width(),height:$('#nesan_img').height(), backgroundImage : 'url('+$('#nesan_img').attr('src')+')' });
	$('#nesan_img').css({display:'none'});
	
	
	$.getJSON("ajax.php?task=mapinfo&id="+pageid,"",function(data,textStatus){
		$.each(data, function(i,item){								
			$.each(item.mapinfo,function(j,info){
				acr = $('<a rel="'+ item.articale_id +'" href="#" alt="'+ item.title +'"></a>').css({left:parseInt(info[0]),top:parseInt(info[1]),width:parseInt(info[2]),height:parseInt(info[3])});//,opacity:0.4
				

				acr.click(function(){
					if(login)
					{
						nw=window.open('articale.php?id='+$(this).attr('rel'),'articwin','scrollbars,status=no,menubar=no,height=400,width=500'); nw.focus();
					}
					else
					{
						alert('Please login view this content');
						window.location.href = 'login.php';
					}
				});
				
				
				
				
				acr.addClass('popupwindow');
				if(item.type=='Image'){
					acr.addClass('image');
					acr.mouseover(function(){ rel = $(this).attr('rel'); $("#nesan_img_map .image[rel='"+ rel +"']").addClass('imagehover'); });
					acr.mouseout(function(){ rel = $(this).attr('rel'); $("#nesan_img_map .image[rel='"+ rel +"']").removeClass('imagehover'); });
					acr.mouseover(function(){
						$("#tooltip").stop();
						$("#tooltip").fadeOut('fast');						   
					});
					
					
				}else{		
					acr.addClass('text');
									
					acr.mouseover(function(){
						$("#tooltip").stop();
						rel = $(this).attr('rel'); $("#nesan_img_map .text[rel='"+ rel +"']").addClass('texthover');
						pos2 =  $("#nesan_img_map .text[rel='"+ rel +"']").position();
						$("#tooltip").css({left:pos2.left+pos.left+10,top:pos2.top+pos.top-100}).fadeIn('normal',function(){$("#tooltip").css({opacity:1});});
						$("#tooltip_in").html('<span class="tooltip_title">'+$(this).attr('alt')+'</span>');
													
					});
					acr.mouseout(function(){
						$("#tooltip").stop();
						rel = $(this).attr('rel'); $("#nesan_img_map .text[rel='"+ rel +"']").removeClass('texthover');
						$("#tooltip").fadeOut('fast');					   
					});					
					
					
				}
				$('#nesan_img_map').append(acr);
				
				
			});
			
			if(item.type=='Condolence'){
				cmap =  $("#nesan_img_map .text[rel='"+ item.articale_id +"']");
				pos2 = cmap.position();
				condo = $('<a ref="'+ item.articale_id +'" class="condolence" href="#">Submit Condolence</a>');
				condo.css({left:pos2.left+5,top:pos2.top+cmap.height()-40,padding:0});				
				condo.mouseover(function(){	rel = $(this).attr('ref'); $("#nesan_img_map .text[rel='"+ rel +"']").addClass('texthover');	});
				condo.mouseout(function(){	rel = $(this).attr('ref'); $("#nesan_img_map .text[rel='"+ rel +"']").removeClass('texthover');		});				
				condo.click(function(){
					if(login){
						nw=window.open('condolence.php?task=submit&id='+$(this).attr('ref'),'articwin','scrollbars,status=no,menubar=no,height=800,width=620'); nw.focus();
					}else{
						alert('Please login view this content'); window.location.href = 'login.php';
					}
				});
				
				condo2 = $('<a ref="'+ item.articale_id +'" class="condolence" href="#">View Condolence</a>');
				condo2.css({left:pos2.left+5,top:pos2.top+ cmap.height()-15,padding:0});				
				condo2.mouseover(function(){	rel = $(this).attr('ref'); $("#nesan_img_map .text[rel='"+ rel +"']").addClass('texthover');	});
				condo2.mouseout(function(){	rel = $(this).attr('ref'); $("#nesan_img_map .text[rel='"+ rel +"']").removeClass('texthover');		});				
				condo2.click(function(){
					if(login){
						nw=window.open('condolence.php?task=condolence&id='+$(this).attr('ref'),'articwin','scrollbars,status=no,menubar=no,height=800,width=620'); nw.focus();
					}else{
						alert('Please login view this content');	window.location.href = 'login.php';
						
					}
				});				
				$('#nesan_img_map').append(condo);			
				$('#nesan_img_map').append(condo2);
		    }
		});
	});
}


$(document).ready(function () {
	$('#nesan_img').load(function (event) { load_map(); });
	
	if(page_list.length >0)
	$('#nesan_img').attr('src','uploads/images/'+page_list[cur_page][1]);
});
