// JavaScript Document

// flag state
// 1 = vic
// 2 = nsw
// 3 = wa
// 4 = qld

var flag = 0;

$(document).ready(function()
{
	
	//Create jsGraphics object
    var gr = new jsGraphics(document.getElementById("lines"));

    //Create jsPen object
    var pen = new jsPen(new jsColor("black"), 1);
	
    //Draw a Line between 2 points
    var ptStart;
    var ptEnd;
	
	var getMarginTop = 0;
	var getMarginRight = 0;
	
	$('#areaPopup').hide();
	$('.popupHover').hide();
	$('.popupHover').css('z-index', '20');
	
	// enlarge thumbnails
	$('.areaDot').css({'cursor':'pointer'});
	
	$('#btnAreaClose').click(
	function()
	{
		$('#areaPopup').fadeOut('slow');
		$('#areaPopupBG').fadeOut('slow');
		gr.clear();
	});
	
	$('#btnAreaClosePopup').click(
	function()
	{
		$('.popupHover').hide();
		gr.clear();
	});
	
	function setAreaContent(obj)
	{
		$(obj).css('display', 'block');
	}
	
	function removeAreaContent()
	{
		$('#vicContent').css('display', 'none');
		$('#nswContent').css('display', 'none');
		$('#waContent').css('display', 'none');
		$('#qldContent').css('display', 'none');
		$('#saContent').css('display', 'none');
		$('#actContent').css('display', 'none');
	}
	
	$('#linkVic').click(function()
	{
		removeAreaContent();
		setAreaContent('#vicContent');
		$('.areaContentHeader').html('victoria service areas.');
	});
	
	$('#linkQld').click(function()
	{
		removeAreaContent();
		setAreaContent('#qldContent');
		$('.areaContentHeader').html('queensland service areas.');
	});
	
	$('#linkWa').click(function()
	{
		removeAreaContent();
		setAreaContent('#waContent');
		$('.areaContentHeader').html('western australia service areas.');
	});
	
	$('#linkNsw').click(function()
	{
		removeAreaContent();
		setAreaContent('#nswContent');
		$('.areaContentHeader').html('new south wales service areas.');
	});
	
	$('#linkSa').click(function()
	{
		removeAreaContent();
		setAreaContent('#saContent');
		$('.areaContentHeader').html('south australia service areas.');
	});
	
	$('#linkAct').click(function()
	{
		removeAreaContent();
		setAreaContent('#actContent');
		$('.areaContentHeader').html('australia capital territory service areas.');
	});
	
	$('#btnAreaClick').click(function()
	{
		$('#areaPopup').fadeIn('slow');
		$('#areaPopupBG').fadeIn('slow');
		$('#areaPopupBG').animate({opacity:0.5},1000);
		$('.popupHover').fadeOut('slow');
		gr.clear();
		
		removeAreaContent();
		
		switch (flag)
		{
			case 1:
			setAreaContent('#vicContent');
			break;
			
			case 2:
			setAreaContent('#nswContent');
			break;
			
			case 3:
			setAreaContent('#waContent');
			break;
			
			case 4:
			setAreaContent('#qldContent');
			break;
		}
		
	});
	
	$('#areaPopupBG').click(function()
	{
		$('#areaPopup').fadeOut('slow');
		$('#areaPopupBG').fadeOut('slow');
		gr.clear();
	});
	
	$('.areaDot').hover(
	function()
	{
		if (getMarginTop == 0 || getMarginTop != parseInt($(this).css("margin-top")))
			getMarginTop = parseInt($(this).css("margin-top"));	
		
		if (getMarginRight == 0 ||  getMarginRight != parseInt($(this).css("margin-right")))
			getMarginRight = parseInt($(this).css("margin-right"));
		
		// clear lines for redraw
		gr.clear();
		
		// draw lines and popup
		switch ($(this).attr('id'))
		{
			case $('#dot01').attr('id'):
			{
				flag = 1;
    			ptStart = new jsPoint((-1) * (getMarginRight + 15), getMarginTop + 15);
				ptEnd = new jsPoint((-1) * (getMarginRight + 130), getMarginTop + 80);
				$('.popupHover').show();
				$('.popupHover').css("margin-right", getMarginRight + 125);
				$('.popupHover').css("margin-top", getMarginTop + 75);
				$('.contentText').html('we service over ' + 270 + ' suburbs in ' + 'NSW' + ' alone?');
				$('.areaContentHeader').html('new south wales service areas.');
				$('.areaExtraText').html('to see if your suburb is listed with us.');
				$('#btnAreaClick').show();
			}
			break;
			case $('#dot02').attr('id'):
			{
				flag = 2;
    			ptStart = new jsPoint((-1) * (getMarginRight + 15), getMarginTop + 15);
				ptEnd = new jsPoint((-1) * (getMarginRight + 150), getMarginTop + 15);
				$('.popupHover').show();
				$('.popupHover').css("margin-right", getMarginRight + 145);
				$('.popupHover').css("margin-top", getMarginTop + 10);
				$('.contentText').html('we service over ' + 140 + ' suburbs in ' + 'VIC' + ' alone?');
				$('.areaContentHeader').html('victoria service areas.');
				$('.areaExtraText').html('to see if your suburb is listed with us.');
				$('#btnAreaClick').show();
			}
			break;
			case $('#dot03').attr('id'):
			{
				flag = 0;
    			ptStart = new jsPoint((-1) * (getMarginRight + 15), getMarginTop + 15);
				ptEnd = new jsPoint((-1) * (getMarginRight + 60), getMarginTop + 90);
				$('.popupHover').show();
				$('.popupHover').css("margin-right", getMarginRight + 55);
				$('.popupHover').css("margin-top", getMarginTop + 85);
				$('.contentText').html('we\'re coming soon to service your area!');
				$('.areaExtraText').html('');
				$('#btnAreaClick').hide();
			}
			break;
			case $('#dot04').attr('id'):
			{
				flag = 3;
    			ptStart = new jsPoint((-1) * (getMarginRight + 15), getMarginTop + 15);
				ptEnd = new jsPoint((-1) * (getMarginRight + 60), getMarginTop + 110);
				$('.popupHover').show();
				$('.popupHover').css("margin-right", getMarginRight + 55);
				$('.popupHover').css("margin-top", getMarginTop + 105);
				$('.contentText').html('we service over ' + 120 + ' suburbs in ' + 'WA' + ' alone?');
				$('.areaContentHeader').html('western australia service areas.');
				$('.areaExtraText').html('to see if your suburb is listed with us.');
				$('#btnAreaClick').show();
			}
			break;
			case $('#dot05').attr('id'):
			{
				flag = 4;
    			ptStart = new jsPoint((-1) * (getMarginRight + 15), getMarginTop + 15);
				ptEnd = new jsPoint((-1) * (getMarginRight + 170), getMarginTop - 80);
				$('.popupHover').show();
				$('.popupHover').css("margin-right", getMarginRight + 165);
				$('.popupHover').css("margin-top", getMarginTop - 85);
				$('.contentText').html('we service over ' + 130 + ' suburbs in ' + 'QLD' + ' alone?');
				$('.areaContentHeader').html('queensland service areas.');
				$('.areaExtraText').html('to see if your suburb is listed with us.');
				$('#btnAreaClick').show();
			}
			break;
		}
		
		// draw lines
   		gr.drawLine(pen, ptStart, ptEnd);
		
		// enlarge dots
		$(this).css({'z-index' : '20'});
		$(this).animate({
				marginTop:getMarginTop + (-5) + 'px',
				marginRight:getMarginRight + (-5) + 'px',
				width:'41px'},
				0);	
	},
	function()
	{
		$(this).animate({
				marginTop:getMarginTop + 'px',
				marginRight:getMarginRight + 'px',
				width:'31px'},
				0);
		$(this).css({'z-index' : '0'});
	});
});