/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 185 2009-02-09 21:51:12Z emartin24 $
 *
 */

$(document).ready(function () {
	$('input.openModal, a.openModal').click(function (e) {
		e.preventDefault();
		$('#basicModalContent').modal({onOpen: createIframe()});
	    $('#simplemodal-container').css({'float' : 'left', 'width' : '900px', 'height' : '615px'});
	});
	
	$(".person").click(function(){
	    $(this).parent().css("height", "195px");
	    $(this).parent().next().fadeIn();
        $(this).mouseout(function(){
            $(this).parent().css("height", "186px");
            $(this).parent().next().fadeOut();
        });
	    return false;
	});
});

function openModal(page, wWidth, wHeight){
	$('#basicModalContent').modal({onOpen: createIframe(page, wWidth, wHeight)});
    $('#simplemodal-container').css({'float' : 'left', 'width' : wWidth+"px", 'height' : wHeight+"px"});
    return false;
}

function createIframe(page, wWidth, wHeight){
    //alert("DEBUG || start making content");
    var countKids = $("#basicModalContent").children().size();
    var mapContainer = document.getElementById("basicModalContent");
    var el = document.createElement("iFrame");
    if(countKids == 0){
        el.name="myIFrame";
        el.id="myIFrame";
        el.src = setSrc(page);        
        if (wWidth == undefined) {
            el.width = 875;
        }
        else {
            el.width = wWidth - 5;
        }
        if (wHeight == undefined) {
            el.height = 605;
        }
        else {
            el.height = wHeight - 10;
        }
        el.border = 0;
        el.frameBorder = 0;
        mapContainer.appendChild(el);
    }else{
        $("#basicModalContent").children().remove();
        el.name="myIFrame";
        el.id="myIFrame";
        el.src = setSrc(page);        
        el.width = 875;
        el.height = 605;
        el.border = 0;
        el.frameBorder = 0;
        mapContainer.appendChild(el);
    }
    return true;
}

function setSrc(page){
    var pageSrc;
    if(page == undefined) {pageSrc = "map.asp";}
    else if(page == "map") {pageSrc = "map.asp";}
    else if(page == "help") {pageSrc = "howto.asp";}
    else if(page == "shipping") {pageSrc = "shipping_list.asp";}
    else {pageSrc = page;}
    return pageSrc;
}
