/**
 * iframe.js
 * 
 * @author Charles Peterson, artistan.org
 * @license MIT-licence
 * @version 0.1
 * @updated-on 10-30-2006
 * @projectDescription jquerified iframe<-->parent selection
 *
 */

/**
 * Get the top frame elements
 * This is where to call functions on frames.
 *
 * @example $(".myIframes").Frame();
 *
 * @name Frame
 * @type jQuery.fn
 * @cat func
 * @return the frame elements from within i/frame tags.
 */
$.fn.Frame = function() {
    var Frs = [];
    this.each(
        function(){
            if(!$(this).is("iframe") && !$(this).is("frame")){
                ;/* don't include */
            } else {
                var frs = null;
                if (this.contentWindow) { /* NS6, IE5.5 and IE6 */
                    fr = this.contentWindow;
                } else if (this) { /* IE5 */
                    fr = this;
                } else {
                    alert("damn");
                    return null;
                }    
                if(fr){
                    Frs.push(fr);
                }
            }
        }
    );
    return $(Frs);
};

/**
 * Get the document elements from a i/frame
 *
 * @example $(".myIframes").FrameDocument();
 *
 * @name FrameDocument
 * @type jQuery.fn
 * @cat func
 * @return the document elements from within i/frame tags.
 */
$.fn.FrameDocument = function() {
    var Docs = [];
    this.each(
        function(){
            if(!$(this).is("iframe") && !$(this).is("frame")){
                // don't include
            } else {
                var doc = null;
                if (this.contentDocument) { // For NS6
                    doc = this.contentDocument; 
                } else if (this.contentWindow) { // For IE5.5 and IE6
                    doc = this.contentWindow.document;
                } else if (this.document) { // For IE5
                    doc = this.document;
                } else {
                    alert("damn");
                    return null;
                }   
                if(doc){
                    Docs.push(doc);
                }
            }
        }
    );
    return $(Docs);
};

/**
 * Get the body elements from a i/frame
 *
 * @example $(".myIframes").FrameBody();
 *
 * @name FrameBody
 * @type jQuery.fn
 * @cat func
 * @return the body elements from within i/frame tags.
 */
$.fn.FrameBody = function() {
    return this.FrameDocument().children().children("body")
};


/**
 * Get the Parent of the Frame element
 * This is where you could call parent functions.
 *
 * @example $(".something_in_a_frame").FrameParent();
 * @example par = $('#something_in_a_frame').FrameParent().each(function(){this.parentFunc();});
 *
 * @name FrameParent
 * @type jQuery.fn
 * @cat func
 * @return the parent element from within i/frame tags.
 */
$.fn.FrameParent = function(){
    return $(parent);
};

/**
 * Get the Parent Document of the Frame element
 *
 * @example $(".something_in_a_frame").FrameParentDoc();
 *
 * @name FrameParentDoc
 * @type jQuery.fn
 * @cat func
 * @return the parent document element from within i/frame tags.
 */
$.fn.FrameParentDoc = function(){
    return $(parent.document);
};

/**
 * Get the Parent Body of the Frame element
 *
 * @example $(".something_in_a_frame").FrameParentBody();
 *
 * @name FrameParentBody
 * @type jQuery.fn
 * @cat func
 * @return the parent body element from within i/frame tags.
 */
$.fn.FrameParentBody = function(){
    return $(parent.document.body);
};
