point_features = {
	'_1':{
		'title':'one title',
		'type':'1',

		'link':'http://www.google.com',
		'text':'For those of you who aren’t grad students, you will see a “-” under “Grad Project”. Don’t yed having you as students and I hope you enjoyed having me as an instructor.'
	},
	'_2':{
		'title':'two title',
		'type':'2',
		'image':'c_map/gfx/2.jpg',
		'link':'http://www.google.com',
		'text':'For those of you who aren’t grad students, you will see a “-” under “Grad Project”. Don’t  having you as students and I hope you enjoyed having me as an instructor.'
	},
	'_3':{
		'title':'three title',
		'type':'3',
		'image':'c_map/gfx/3.jpg',
		'link':'http://www.google.com',
		'text':'For those of you who aren’t grad students, you will see a “-” under “Grad Project”. Don’t worry about that, it’s not affecting the calculation of your grade. If anyone would like Exam 3 (or any earlier   instructor.'
	}
}


click_boxes = {
	'something':{
		'top_left_x':'111',
		'top_left_y':'111',
		'bottom_right_x':'222',
		'bottom_right_y':'222',
		'path_to_map':'mapofoz'
	},
	'blahblah':{
		'top_left_x':'150',
		'top_left_y':'150',
		'bottom_right_x':'333',
		'bottom_right_y':'333',
		'path_to_map':'mapofazeroth'
	},
	'tomisacat':{
		'top_left_x':'444',
		'top_left_y':'444',
		'bottom_right_x':'555',
		'bottom_right_y':'555',
		'path_to_map':'mapofnorthrend'
	}
}





// =============================================================================

// Global Variables
//==============================================================================
var popup_x = 312;
var popup_y = 100; 




$(document).ready(function(){
	window.onload=function(){
		insert();
		bulletHandle();
		createClickBoxes();
		actions(); // Be sure this is called last
	};
});


// Click Boxes for clustered point features
//==============================================================================
function createClickBoxes(){
	for(n in click_boxes){

		var div_width = click_boxes[n].bottom_right_x - click_boxes[n].top_left_x;
		var div_height = click_boxes[n].bottom_right_y - click_boxes[n].top_left_y;

		// CREATE CLICKBOXES
		$('#_data_buffer').append('<div class="clickbox clickbox_no_hover" style="width:'+ div_width +'px; height:'+ div_height +
		'px; left:' + click_boxes[n].top_left_x + 'px; top:' + click_boxes[n].top_left_y + 'px;" name="'+ 
		click_boxes[n].path_to_map +'"></div>');

		// CREATE SECONDARY MAP DIVS FOR EACH CLICKBOX
		$('#_data_buffer').append('<div class="secondarymap" style="width:'+ div_width +'px; height:'+ div_height +
		'px; left:' + click_boxes[n].top_left_x + 'px; top:' + click_boxes[n].top_left_y + 'px;" id="'+ 
		click_boxes[n].path_to_map +'"></div>');

	}
}

// Insert Initial Content Into Page
//==============================================================================
function insert(){
	$('#_close_box').empty().append('<a href="#" id="_close_c_map">Close</a>'); // Insert close map link
}

// jQuery Actions
//==============================================================================
function actions(){
	$('#_open_c_map').click(function(){openMap()}); //CLICK ON MINI MAP


	$('#_close_c_map').click(function(){closeMap()}); // CLOSE MAP LINK


	// BULLET MOUSEOVER/OUT & CLICK
	$('.bullet').mouseover(function(){
		var title = $(this).attr('name');
		$('#_descriptor').empty().append(title);
	})
	.mouseout(function(){
		$('#_descriptor').empty();
	})
	.click(function(){
		var which = $(this).attr('id');
		openPopUp(which);
	});


	$('#popup').draggable(); // MAKE POPUPS DRAGGABLE


	$('.closepop').click(function(){closePopUp();}); // CLOSE POPUP


	// Mouseover/out Popups
	$('#popup').mouseover(function(){	// HIGHLIGHT POPUPS ON MOUSEOVER/OUT
		$('#poptit').css({'background-position':'-276px 0', 'color':'#333333'});
	}).mouseout(function(){
		$('#poptit').css({'background-position':'0px 0', 'color':'#666666'});
	});

	// Click Boxessub_map_name
	$('.clickbox').click(function(){
		closePopUp();
		var sub_map_name = $(this).attr('id');
		//alert(path);
		$('.secondarymap').show();
		openSubMap(sub_map_name);

	}).mouseover(function(){
		$('#_descriptor').empty().append('Click to enlarge');
		$(this).removeClass('clickbox_no_hover');
		$(this).addClass('clickbox_hover');
		var xxx = $(this).attr('id')
		console.log(xxx);
	}).mouseout(function(){
		$('#_descriptor').empty();
		$(this).addClass('clickbox_no_hover');
		$(this).removeClass('clickbox_hover');
	});
}

function openSubMap(sub_map_name){
	console.log(sub_map_name);
	$('#' + sub_map_name).css({'background-color':'pink'});
}


// Open Map
//==============================================================================
function openMap(){
	$('#container').css({
		'filter':'alpha(opacity=30)',
		'-khtml-opacity':'0.3',
		'-moz-opacity':'0.3',
		'opacity':'0.3'
	});

	$('#c_map_container').show();
}

// Close Map
//==============================================================================
function closeMap(){
	$('#container').css({
		'filter':'alpha(opacity=100)',
		'-khtml-opacity':'1',
		'-moz-opacity':'1',
		'opacity':'1'
	});

	$('#c_map_container').hide();
}

// Bullet Handeling
//==============================================================================
function bulletHandle(){
	$('.bullet').each(function(){
		var id = $(this).attr('id') + ""; //_001A
		var xy = $(this).attr('rel').split('-'); //[345][32]
		var x = xy[0] -5; // ADJUST FOR ICON
		var y = xy[1] -5; // ADJUST FOR ICON
		var type = point_features[id].type; //GRAB TYPE OF BULLET
		var title = point_features[id].title; //GRAB TITLE FOR BULLET

		if(typeof point_features[id].type !== 'undefined'){	//SET COLOR
			if(point_features[id].type === '1'){$(this).addClass('purple')}
			else if(point_features[id].type === '2'){$(this).addClass('orange')}
			else if(point_features[id].type === '3'){$(this).addClass('blue')}
			else if(point_features[id].type === '4'){$(this).addClass('green')}
			else if(point_features[id].type === '5'){$(this).addClass('gray')}
			else if(point_features[id].type === '6'){$(this).addClass('yellow')}
		}else{$(this).addClass('green');} //SET DEFUALT

		$(this).css({'left' : x, 'top' : y, 'position': 'absolute'});	//SET POSITION

		$(this).attr({name: title});	// SET TITLE
	});
}

// Pop Up
//==============================================================================
function openPopUp(which){
	$('#popup').fadeOut(400,
		function(){
			$('#popname').empty();
			$('#popcont').empty();

			// Popup Image
			if(typeof point_features[which].image !== 'undefined'){
				$('#popcont').append('<img src="'+
				point_features[which].image+'" alt="'+
				point_features[which].title+'" title="'+
				point_features[which].title+
				'" id="popimage" align="right">');
			}

			// Popup Title
			if(typeof point_features[which].title !== 'undefined'){
				$('#popcont').append('<b>'+
				point_features[which].title+'</b>');
			}

			// Popup Text
			if(typeof point_features[which].text !== 'undefined'){
				$('#popcont').append('<p>'+
				point_features[which].text+'</p>');
			}


			// Popup Link
			if(typeof point_features[which].link !== 'undefined'){
				$('#popcont').append('<p><a href="'+
				point_features[which].link+'">Link</a></p>')
			}

			$('#popup').animate({'left': popup_x, 'top': popup_y},1,
				function(){$('#popup').fadeIn();}
			);
		}
	);
}

// Pop Up
//==============================================================================
function closePopUp(){
	$('#popup').fadeOut(400);
}



























