$(document).ready(function(){
	$('#spot_request_link').live('click', spotrequest);
	
	$('#area_spot_my_world_request').jqm({
        trigger: '#spot_my_world_link',
        overlay: 30, 
        overlayClass: 'jqmOverlay',
        onShow: function(hash) {
        	_show(hash);
        	$('#quickme_window .close_quickme_window').click();
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        },
        onHide: function(hash){
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
            hash.w.hide();
            hash.o.remove();
        }
	});

	$('#buddies_link_fromquick').live('click',  function(){ $('#buddies_link').click(); });
	
/*
    heightDivDescription();
*/
	$('#area_vote_me').jqm({
        trigger: '#vote_me_link',
        overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
        overlayClass: 'jqmOverlay',
        onShow: function(hash) {
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        	_show(hash);
        },
        onHide: function(hash){
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
        	
            hash.w.hide();
            hash.o.remove();
            $('#vote_user_val').val('10');
        }
	});
	
	$('#area_offence').jqm({
        trigger: '#offence_link',
        overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
        overlayClass: 'jqmOverlay',
        onShow: function(hash) {
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        	_show(hash);
        },
        onHide: function(hash){
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
            hash.w.hide();
            hash.o.remove();
            $('#error_offence_comment').empty();
            $('#offence_comment').val('');
        }
    });
	
	$('#area_buddy').jqm({
        trigger: '#buddies_link',
        overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
        overlayClass: 'jqmOverlay',
        //onShow: _show
        onShow: function(hash) {
        	_show(hash);
        	$('#quickme_window .close_quickme_window').click();
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        },
        onHide: function(hash){
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
            hash.w.hide();
            hash.o.remove();
        }

	});

    $("#area_contact_me").jqm({
        trigger: '#contact_me_link_popup',
        overlay: 30,
        overlayClass: 'jqmOverlay',
        onShow: function(hash) {
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        	_show(hash);
        },
        onHide: function(hash){
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
            hash.w.hide();
            hash.o.remove();
        }
    });

	$('#waiting_buddies_link').live('click', function() {
		alert(waiting_buddies_link_message);	
		return false;
	});
	$('#waiting_buddies_link_fromquick').live('click', function() {
		alert(waiting_buddies_link_message);	
		return false;
	});

	
	
	
	$('[id=^area_] > a.register_link').click(function(){
	    href = $(this).attr('href');
	    document.location.href = href;
	});

    $("#quickme_window").jqm({
        trigger: '#quick_me_link_popup',
        overlay: 30,
        overlayClass: 'jqmOverlay',
        onShow: function(hash) {
        	$('#about_myself').find('embed').css('visibility', 'hidden');
        	$('#blog_message').find('embed').css('visibility', 'hidden');
        	_show(hash);
        },
        onHide: function(hash) {
        	$('#about_myself').find('embed').css('visibility', 'visible');
        	$('#blog_message').find('embed').css('visibility', 'visible');
            hash.w.hide();
            hash.o.remove();
        }
    });
    $("#join_meet_me").jqm({
        trigger: '#join_meet_me1',
        overlay: 30,
        overlayClass: 'jqmOverlay',
        onShow: _show
    });

    $('#add_message').jqm({
	    overlay: 30,
	    overlayClass: 'jqmOverlay',
            onShow: _show
    });

	$('#quickme_window .close_quickme_window').click(function() {$("#quickme_window").hide();})

	try {
    	$('#joinmeetmeTrigger').live('click', joinmeetme);
	} catch (e) {};
	
    heightDivBestBuddies();
});

function spotrequest() {
	// spotmyworld invite empty message
	$.ajax({
		type: "POST",
		url: "/"+user_worldlink+"/world/spot/spotmyworldrequest",
		data: "spotrequest="+1,
		async: false,
		dataType: "json",
		success: function(resp) {}
	});	
	$('#area_spot_my_world_request .close_area_spot_my_world_request').click();
}


function heightDivBestBuddies() {
    var content = $('div.bestbuddies .fotoBlock260:eq(0)').html();
    var h1 = 0, hf = 0, hs = 0, h = 0;
    if ( content != null ) {
        for (var i = 0; i <= 7; i++) {
            h1 = $('div.bestbuddies .fotoBlock260:eq(' + i + ')').height();
            if ( i <= 3 ) {
                if ( h1 != null ) {
                    if ( h1 > hf ) {
                        hf = h1;
                    }
                }
            } else {
                if ( h1 != null ) {
                    if ( h1 > hs ) {
                        hs = h1;
                    }
                }
            }
        }
        h = hf + hs;
    }
    if ( h > 220 ) {
        $("div.bestbuddies").css('height', (h + 50) + 'px');
    }
}

function heightDivDescription() {
    var content = $("#about_myself").html();
    if ( content != null ) {
        var height_div = $("#about_myself").height();
        if ( height_div > 450 ) {
            $("#about_myself").css('height', '450px');
        } else {
            $("#about_myself").css('height', 'auto');
        }
    }
}
