/*
 * SimpleModal Contact Form
 * 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: jQueryId: contact.js 212 2009-09-03 05:33:44Z emartin24 jQuery
 *
 */

function loadjscssfile(filename, filetype){
    if (filetype == "js") { // filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    } else if (filetype == "css") { // filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

var mediatype;
jQuery(document).ready(function () {
    jQuery('.showTestimonialPopup').click(function (e) {
        if(testimonial.length == 0) {
            return false;
        }

        section = "testimonial";
        e.preventDefault();

        // load the contact form using ajax
        scriptfile = '/player.php';
        if (mediatype == 'audio') {
            scriptfile = '/audioplayer.php';
        }
        jQuery.get(requestPath + scriptfile + "?file=" + testimonial + "&title=" + vtitle, function(data){


        // create a modal dialog with the data
        jQuery(data).modal({
            closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
            position: ["15%",],
            overlayId: 'contact-overlay',
            containerId: 'contact-container',
            onOpen: contact.open,
            onShow: contact.show,
            onClose: contact.close
        });
        if (mediatype == 'audio') {
            document.getElementById('contact-container').style.background = 'url(' + requestPath + '/images/SBaudioplayerBck.png)';
            document.getElementById('contact-container').style.height = '155px';
            document.getElementById('simplemodal-data').style.height = '155px';
            document.getElementById('ccc').style.height = '95px';
            var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
            cctop = h/2-80;
            document.getElementById('contact-container').style.top = cctop + 'px';
        }

    });
});

    // preload images
    var img = ['cancel.png', 'form_bottom.png', 'form_top.png', 'loading.gif', 'send.png'];
    jQuery(img).each(function () {
        var i = new Image();
        i.src = requestPath + '/images/' + this;
    });
});



var contact = {
	message: null,
	open: function (dialog) {

        // dynamically determine height
        var h = 350;
		var title =jQuery('#contact-container .contact-title').html();
		jQuery('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					jQuery('#contact-container .contact-content').animate({
						height: h
					}, function () {
                        jQuery('#contact-container .contact-title').html(title);
						jQuery('#videoFrame').show();
						});
					});
				});
			});

	},
	show: function (dialog) {


	},
	close: function (dialog) {

        jQuery('#videoFrame').hide();

		jQuery('#contact-container .contact-message').fadeOut();
		jQuery('#contact-container .contact-title').html('Closing...');
		jQuery('#contact-container form').fadeOut(200);
		jQuery('#contact-container .contact-content').animate({
			height: 55
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						jQuery.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	}
};
jQuery.noConflict();
