( function( $ )
    {
        $.fn.wresize = function( f )
        {
            version = '1.1';
            wresize = {
                fired: false,
                width: 0
            };

            function resizeOnce()
            {
                if ( $.browser.msie )
                {
                    if ( ! wresize.fired )
                    {
                        wresize.fired = true;
                    }
                    else
                    {
                        var version = parseInt( $.browser.version, 10 );
                        wresize.fired = false;
                        if ( version < 7 )
                        {
                            return false;
                        }
                        else if ( version == 7 )
                        {
                            var width = $( window ).width();
                            if ( width != wresize.width )
                            {
                                wresize.width = width;
                                return false;
                            }
                        }
                    }
                }

                return true;
            }

            function handleWResize( e )
            {
                if ( resizeOnce() )
                {
                    return f.apply(this, [e]);
                }
            }

            this.each( function()
            {
                if ( this == window )
                {
                    $( this ).resize( handleWResize );
                }
                else
                {
                    $( this ).resize( f );
                }
            } );

            return this;
        };

    } ) ( jQuery );

var currentTab = '';
function openTab(id) {
    isPaused = true;
    currentTab = id;
    jQuery('.sub-tab').hide();

    var set_id = '#' + id + '-sub';
    jQuery(set_id).show();
    jQuery('#nav ul li#' + id + ' a:first').css("background-image", "url(layout/nav-" + id + "-hover.gif)");
}

function closeTabs() {
    isPaused = false;
    jQuery('.sub-tab').hide();
    
    if (currentTab != "") {
        jQuery('#nav ul li#' + currentTab + ' a:first').css("background-image", "url(layout/nav-" + currentTab + ".gif)");
    }
    currentTab = '';
}

function switchImg(img) {
    jQuery("#main-img").attr("src","layout/" + img);
    currentImg++;
}

var isPaused = false;
var imgArray = ['img.jpg','Girl-with-B-Ball.jpg','Golf-Balls.jpg','Beach-chairs.jpg'];
var currentImg = 0;

function rotateImages() {
    if (isPaused == false) {
        if (currentImg == imgArray.length) {
            currentImg = 0;
        }

        jQuery("#main-img").fadeOut(function() {
            switchImg(imgArray[currentImg]);
        }).fadeIn();
    }
    setTimeout("rotateImages()",4000);
}

function autoIframe(frameId){
    try{
        frame = document.getElementById(frameId);
        innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;

        if (innerDoc == null){
            frame.height = document.all[frameId].clientHeight + document.all[frameId].offsetHeight + document.all[frameId].offsetTop;
        }
        else{
            objToResize = (frame.style) ? frame.style : frame;
            objToResize.height = innerDoc.body.scrollHeight + 25;
        }
    } catch(err){
    }
}

jQuery(document).ready(function() {
    jQuery("nav#nav a").click(function() {
        var current_redirect = this.href;
        var current_url = this.title;

        if (this.title != "") {
            jQuery("#url_form").attr("action",current_redirect);
            jQuery("#goto").val(this.title);
            jQuery("#url_form").submit();
        }
        return false;
    });
    rotateImages();
});

function resizeIframe() {
    var height = jQuery(window).height();
    var maxHeight = height - 178;
    jQuery("#iframe").height(maxHeight);
    jQuery("#iframe").width(jQuery(window).width());
}

jQuery(document).ready(function(){
    resizeIframe();
});

jQuery(window).resize(function () {
    resizeIframe();
});

window.onresize = function(){
    resizeIframe();
}

//document.body.onresize = function (){
//    resizeIframe();
//}

$( window ).wresize( resizeIframe );
