var $bubble_para = null, $bubbles = null, $bubble_middle = null, $bubble_left = null, $bubble_right = null, $bubble_bottom = null;
function animateSearchButton(){
    $("form img").each(function(){        
		var $prev = $(this).prev();
		if($prev.is("input[type=submit]")){
			$prev.hide();
			$(this).click(function(){ $(this).prev().click(); });            
		}		
	});   
    $("form a.submit_link").each(function(){
        var $prev = $(this).prev();
		if($prev.is("input[type=submit]")){
        	$prev.hide();
			$(this).click(function(){ $(this).prev().click(); });
		}else{
            var $next = $(this).next();
		    if($next.is("input[type=submit]")){
                $next.hide();
                $(this).click(function(){ $(this).next().click(); });
		    }
        }
	});
}
function promoboxes(){
    $('#main_feature').cycle({
        fx: 'fade',
        speed: 2250,
        timeout: 8000
    });

    $(function() {
        $(".stop_cycle").click(function() {
            $('#main_feature').cycle('pause');
            return false;
        });

        $(".start_cycle").click(function() {
            $('#main_feature').cycle('resume');
            return false;
        });
     });
}

function promo_gb_boxes(){    
    $('#gouk_main_box_holder').cycle({
        fx: 'fade',
        speed: 2250,
        timeout: 8000
    });

    $(function() {
        $(".stop_cycle").click(function() {
            $('#gouk_main_box_holder').cycle('pause');
            return false;
        });

        $(".start_cycle").click(function() {
            $('#gouk_main_box_holder').cycle('resume');
            return false;
        });
     });
}

function updateBrowseScheduledEvents() {
    
}

function updateSubsector() {
    $("#subsector option").remove();

    var value = $("#sector").val();
    var txt = $("#sector option:selected").text();

    $("#subsector").attr("disabled", true);

    $("#subsector").append("<option value='-1'>Select Sub-Sector</option>");
    if (value != "-1") {
        var hasChildren = false;

        $.each(sectorMap[value], function(i, val) {
            $("#subsector").append("<option value='" + val[1] + "'>" + val[0] + "</option>");
            hasChildren = true;
        });
        
        if (hasChildren) {
            $("#subsector").attr("disabled", false);
        }
    }
}

//When the page is ready do the following functions
$(function() {
    animateSearchButton();

    if($.browser.msie){
        $("input[type=checkbox],input[type=radio]").css("border","0px solid #fff");
    }

	try {
    $('#share_dialog').dialog({
        autoOpen: false,
        bgiframe: true,
        height: 250,
        width: 550,
        resizable: false,
        closeText: 'close',
        modal: true
	});
	} catch(e) {
		//catches js exception if there isn't dialog loaded...so the rest of the script can work
	}

	$(".share_this").click(function() {
        $('#share_dialog').dialog('open');
        return false;
	});

	if($("area").size() > 0) {
		loadMapEvents();
	}


});

function loadMapEvents() {
    $("#map_holder").fadeTo("slow", 1.00);
	if($bubble_para == null) {
		//Caching elements//
		$bubble_para = $("#bubble_middle p");
		$bubbles = $(".bubble");
		$bubble_middle = $("#bubble_middle");
		$bubble_left = $("#bubble_left");
		$bubble_right = $("#bubble_right");
		$bubble_bottom = $("#bubble_bottom");
		$("#city_details_holder").hide();
	}

	if($.browser.mozilla) {
		$(".world #map_holder").css("paddingTop", "15px")
	}
	
	$("area").mousemove(function(e){       

        $bubble_para.html(this.title.replace(" ", "&nbsp;"));
		$bubbles.show();
		var x = -5 + e.pageX;
    	var y = e.pageY - ($bubble_bottom.height() + 3);
		$bubble_bottom.css("top",y).css("left",x);
		y = y - $bubble_left.height() + 5;
		
		x = x - $bubble_para.width() + 10;
		$bubble_middle.css("top", y).css("left",x);
		x = x - $bubble_left.width();
		$bubble_left.css("top", y).css("left", x);
		x = x + $bubble_left.width() + $bubble_middle.width();
		$bubble_right.css("top", y).css("left", x);
		
		
		if(!$("#main_map").data("src")) {
			$("#main_map").data("src", $("#main_map").attr("src"));
		}
		var hover = "#" + this.id + "_hover";
		if ($(hover).size() == 1) {
			$("#main_map").attr("src", $(hover).attr("src"));
		}

	}).mouseout(function(){ 
		$bubbles.hide();
		$("#main_map").attr("src", $("#main_map").data("src"));
	});
	
	$("area.zoom").click(function(){
		var url_id = this.id;
        $("#map_holder").fadeTo("slow", 0.33);
		$("#map_holder").load("/export/getmap.html #sub_map_holder", "id="+ url_id, loadMapEvents);
		return false;
	});
	
	$("area.city").click(function(){
		var city_detail_id = $(this).attr("href");
		$("#city_details_holder").html($(city_detail_id).html());
		$("#city_details_holder").show();
		return false;
	});
	
	$("#city_details_holder .close a").live("click", function() {
		$("#city_details_holder").hide();
		return false;
	});	

}

function floatNone() {
    $(".one_column, .two_column").css("float","none");
    setTimeout("floatLeft()", 20);
}

function floatLeft() {
    $(".one_column, .two_column").css("float","left");
}

