var selectedPerson;
var tmp;
var peopleXMLUrl = "assets/xml/people.xml";

function populatePopUp(person) {
    $('.ourpeople_overlay .meta').html($(person).find('.meta').html());
    $('.ourpeople_overlay .person_header').text($(person).find('h3').text());
    $('.ourpeople_overlay p.role').text($(person).find('.copy p').text());
    $(".person_large img").attr('src',$(selectedPerson).find('img').attr('src').replace('small', 'large'));
    $(".person_large img").attr('alt',$(selectedPerson).find('img').attr('alt'));
}

$(document).ready(function() {

    /* Hide the overlay div to begin with */
    $(".ourpeople_overlay").hide();

    // Initialise tinymce areas
    $().ready(function() {
        $('textarea.tinymce').tinymce({
            script_url: '/Templates/Scripting/tiny_mce/tiny_mce.js',
            theme: "advanced",
            theme_advanced_buttons1: "bold,italic,link,unlink,|,undo,redo,|,code",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_toolbar_location: "bottom",
            theme_advanced_toolbar_align: "center",
            valid_elements: "@[id|class|style|title],p,a[rel|name|href|target|title|class|data-count],strong/b,em/i,br,script[src|type]",
            width: "430px",
            height: "250px",
            content_css: "/Templates/Scripting/tiny_mce/tinymce.css",
            popup_css_add: "/Templates/Scripting/tiny_mce/tinymce_popup.css",
            plugins: "inlinepopups"
        });
    });

    $("a.pop").click(function() {
        selectedPerson = this;
        $('#bg').show();
        tmp = $(this).parent().parent();
        populatePopUp($(this).parent().parent());
        $(".ourpeople_overlay").fadeIn("slow");
        $(".close .closepop").focus();

        return false;
    });

    $(".person h3").click(function() {
        selectedPerson = $(this).parent().parent().find('a.pop');
        $('#bg').show();
        tmp = $(this).parent().parent();
        populatePopUp($(this).parent().parent());
        $(".ourpeople_overlay").fadeIn("slow");
        $(".close .closepop").focus();
        return false;
    });

    $("a.closepop").click(function() {

        $(".ourpeople_overlay").fadeOut("slow");
        $('#bg').hide();
        $(selectedPerson).focus();
        return false;

    });

    if (showLogin) {
        var api = $("div#login").overlay({ oneInstance: false, api: true });
        api.load();
    }
    if (showReg) {
        var api = $("div#registeruser").overlay({ oneInstance: false, api: true });
        api.load();
    }
    if (showEdit) {
        var api = $("div#edituser").overlay({ oneInstance: false, api: true });
        api.load();
    }


    var triggers = $("a.popuplink").overlay({

        // some expose tweaks suitable for modal dialogs
        expose: {
            color: '#333',
            loadSpeed: 400,
            opacity: 0.9
        },

        closeOnClick: false
    });

    $(".addthis").show();


    //var api = $("div#register").overlay({oneInstance: false, api: true}); 
    //api.load(); 

    /*	$("#prompt form").submit(function(e) {

	// close the overlay
    triggers.eq(1).overlay().close();

	// get user input
    var input = $("input", this).val();

	// do something with the answer
    triggers.eq(1).html(input);

	// do not submit the form

	return e.preventDefault();
	
	});*/




    /*		$(".ourpeople_overlay").show("slow", function() {
    this.fadeIn();										  
    });*/

    $(".volBG").click(function(e) {
        var w = Math.round(e.pageX - this.offsetLeft - $(this).parent().parent().position().left); // + "px";

        $(".vol").width(w + "px");

        var vol = Math.round(w / $(this).width() * 100);
        flowplayer().setVolume(vol);
    });


    $("a.viewmore").show();
    $(".moreposts").hide();
    $("a.viewmore").click(function() {
        if ($(this).parent().next()) {
            if ($(this).parent().next().next().attr("class") != "moreposts") {
                $(this).parent().next().find("a.viewmore").hide();
            }
            $(this).parent().next().slideDown(5000);
        }
        $(this).hide();
        return false;
    });





});

var tmp;
function getPeopleXML() {
    $.ajax({
        type: "GET",
        url: peopleXMLUrl,
        dataType: "xml",
        success: function(xml) {
            tmp = xml;
        },
        error: function(xhr, textStatus, errorThrown) {
            tmp = xhr;
        }
    });
}

function ConfirmDeleteEntry() {
    if (confirm('Please confirm you want to remove this entry')) {
        ShowLoading();
        return true;
    }
    else { return false; }
}

function ShowLoading() {
    $('.submitbutton').hide();
    $('.ajaxloader').show();
}


