/******************************************************
	* jQuery plug-in
******************************************************/
(function($) {
    // plugin definition
    $.fn.resize = function(options) {
        var path = '/';

            $.cookie('ft',null,{path: path})
            $.cookie('nh',null,{path: path})
            $.cookie('nw',null,{path: path})
            $.cookie('nl',null,{path: path})
            $.cookie('ie_h',null,{path: path})
            $.cookie('ie_w',null,{path: path})
            $.cookie('wh',null,{path: path})//windowHeight
            $.cookie('ww',null,{path: path})

        // First position object
        var iw = this.children('img').width();
        var ih = this.children('img').height();
        
        var fRatio = ih/iw;

        var mh = 600;
        if (getWindowHeight() > mh) {
            var nh = getWindowHeight();
        }else{
            var nh = mh;

        }
        var nw = Math.round(nh * (1/fRatio));

        if(nw < getWindowWidth()){
            var nl = Math.round((getWindowWidth()-nw)/2);
        }else{
            var nl = 0;
        }

        function browserLessThanIE7(){
            return (/MSIE ((5\\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");
        }
        var ie_h = 0;
        var ie_w = 0;
        if (browserLessThanIE7()) {
            ie_h = 0;
            ie_w = 0;
        }

        var ft = nh - 30 + ie_h;


        if(options){
            this.css("position","absolute");
            this.children('img').css("height","100%");
            this.children('img').css("width","100%");
            $("#footer").css("top",ft);
            $("#content").css("height",nh-200);
            $(".shoppCartDisplay").css("height",nh-200);
            $(".resizeDiv").css("height",nh-200);
            $("#content").css("width",(nw-390));
            this.css("height",nh+ie_h);
            this.css("width",nw+ie_w);
            this.css("left",nl);
            this.css("overflow","hidden");

            if (browserLessThanIE7()) {
                this.css("top","0px");
                this.css("z-index","-1");
            }

            
            $.cookie('isResized',true,{path: path, expires:0.04})
            $.cookie('ft',ft,{path: path, expires:0.04})
            $.cookie('nh',nh,{path: path, expires:0.04})
            $.cookie('nw',nw,{path: path, expires:0.04})
            $.cookie('nl',nl,{path: path, expires:0.04})
            $.cookie('ie_h',ie_h,{path: path, expires:0.04})
            $.cookie('ie_w',ie_w,{path: path, expires:0.04})
            $.cookie('wh',getWindowHeight(),{path: path, expires:0.04})
            $.cookie('ww',getWindowWidth(),{path: path, expires:0.04})
            
        }
//        if($.cookie('isResized')==null){
        
            $.cookie('isResized',true,{path: path, expires:0.04})
            $.cookie('ft',ft,{path: path, expires:0.04})
            $.cookie('nh',nh,{path: path, expires:0.04})
            $.cookie('nw',nw,{path: path, expires:0.04})
            $.cookie('nl',nl,{path: path, expires:0.04})
            $.cookie('ie_h',ie_h,{path: path, expires:0.04})
            $.cookie('ie_w',ie_w,{path: path, expires:0.04})
            $.cookie('wh',getWindowHeight(),{path: path, expires:0.04})//windowHeight
            $.cookie('ww',getWindowWidth(),{path: path, expires:0.04})//windowWidth
//        }
//            alert(nw);
//            alert(getWindowHeight());
//            alert(getWindowWidth());

    };

	
    // private function for debugging
    function debug($obj) {
        if (window.console && window.console.log) {
            window.console.log('Window Width: ' + $(window).width());
            window.console.log('Window Height: ' + $(window).height());
        }
    };
	
    // Dependable function to get Window Height
    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof(window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else {
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
            }
        }
        return windowHeight;
    };
	
    // Dependable function to get Window Width
    function getWindowWidth() {
        //        var windowWidth = 0;
        return $('body').width();
    //
    //        if (typeof(window.innerWidth) == 'number') {
    //            windowWidth = window.innerWidth;
    //        }
    //        else {
    //            if (document.documentElement && document.documentElement.clientWidth) {
    //                windowWidth = document.documentElement.clientWidth;
    //            }
    //            else {
    //                if (document.body && document.body.clientWidth) {
    //                    windowWidth = document.body.clientWidth;
    //                }
    //            }
    //        }
    //        return windowWidth;
    };
})(jQuery);

