/*

iPointer
Copyright (c) 2010 Hemn Chawroka

Version: 1.2

*/
(function($) {

	$.fn.imgPoints = function(n) {

		if(undefined != n){
			notes = n;
		} 

		image = this;

		imgOffset = $(image).offset();
	
		$(notes).each(function(){
			appendnote(this);
		});	
	
		$(image).hover(
			function(){
				$('.point').fadeIn(300);
			},
			function(){
				$('.point').hide();
			}
		);

		addnoteevents();
		
		$(window).resize(function () {
			$('.point').remove();

			imgOffset = $(image).offset();

			$(notes).each(function(){
				appendnote(this);				
			});

			addnoteevents();

		});
	} 
	
	function addnoteevents() {
		$('.point').hover(
			function(){
				$('.point').show();
				$(this).next('.note').fadeIn(300);
				$(this).next('.note').css("z-index", 10000);
			},
			function(){
				$('.point').show();
				$(this).next('.note').fadeOut(300);
				$(this).next('.note').css("z-index", 0);
			}
		);
	}


	function appendnote(note_data){
		
		note_left  = parseInt(imgOffset.left) + parseInt(note_data.x-4);
		note_top   = parseInt(imgOffset.top) + parseInt(note_data.y-4);
		note_p_top = note_top+20;
		if(note_data.url){ var goto = " onclick=\"window.location.href='"+note_data.url+"';\" style=\"cursor:pointer\""; } else { var goto = ""; }
						
		note_area_div = $("<div class='point'"+goto+"></div>").css({ left: note_left + 'px', top: note_top + 'px' });
		
		note_text_div = $('<div class="note" >'+note_data.note+'</div>').css({ left: note_left + 'px', top: note_p_top + 'px'});
	
		$('body').append(note_area_div);
		$('body').append(note_text_div);
	}
})(jQuery);
