﻿// $jdependecies: jQuery [build 1.3.2]

var $j = jQuery.noConflict();

function IsjQueryEnabled() {
    jQueryExists = typeof jQuery != 'undefined';
    // alert('checking for jquery : ' + jQueryExists);
    return jQueryExists;
}

if (IsjQueryEnabled()) {
    $j(document).ready(function(){
        $j('body#home div#boxes div.column div.menu').css({ opacity: 0.7 });
        $j('body#home div#boxes div.column').hover(
            function() { // over
                $j('div.menu', this).fadeTo('normal', 1.0);
            }, 
            function() { // out
                $j('div.menu', this).fadeTo('normal', 0.7);
            } 
        );
        
        // $j('#gcal').click(function() { show_calendar() });;
    });
    
    var calendar_open = false;
    
    (function($j) {
        $j.fn.eqcol = function() {
            var mh = 0;
            $j('div', this).each(function() { if ($j(this).height() > mh) { mh = $j(this).height(); }; });
            $j('div', this).height(mh);
        }
    }) (jQuery);
    
    (function($j) {
        $j.fn.calendar = function(options) {
            var opts = $j.extend({}, $j.fn.calendar.defaults, options);
            var self = this;
            $j(document).click(function() { if (calendar_open) { $j('#overlay, #google-calendar').hide(); calendar_open = false; } });
            return $j(this).each(function() {
                $j(this).click(function(evt) {
                
                    if (!opts.url) return;
                
                    evt.preventDefault();
                    
                    if ($j('#overlay').length > 0)
                    {
						$j('#overlay, #google-calendar').show();
						calendar_open = true;
						return false;
                    }
                    
                    //alert($j(window).height());
                    
                    // get veiwport width and height
                    var vp_w = $j(document).width();
                    var vp_h = $j(document).height();


                    var overlay = $j('<div>');
                    overlay.css({background: '#000', opacity: 0.3, height: vp_h, width: vp_w, position: 'absolute', top: 0, left: 0, zIndex: 90});
                    $j(document.body).append(overlay);
                    overlay.attr('id', 'overlay');
                    overlay.show();
                    
                    var offset = { width: 50, height: 50 };

                    var c_w = vp_w - offset.width * 2;
                    var c_h = $j(window).height() - offset.height * 2;

                    // build html
                    var c_iframe = $j('<iframe>');
                    c_iframe.attr('src', opts.url);
                    
                    c_iframe.css({borderWidth: 0, position: 'absolute', top: offset.height, left: offset.width, zIndex: 99, border: '1px solid #000' });
                    c_iframe.attr('width', c_w);
                    c_iframe.attr('height', c_h);
                    c_iframe.attr('frameborder', '0');
                    c_iframe.attr('scrolling', 'no');
                    $j(c_iframe.document).ready(function() { 
                    });

                    var c_container = $j('<div>');
                    
                    c_container.attr('id', 'google-calendar');
                    
                    c_container.append(c_iframe);
                    
                    
                    // add close button
                    var cl = $j('<a>');
                    var ciw = {width: 40, height: 40 };
                    cl.attr('href', 'javascript:void(0);');
                    var ci = $j('<img>');
                    ci.attr('src', '/common/images/biogasportalen/calendar_close.png');
                    cl.css({position: 'absolute', top: (offset.height / 2) + (ciw.height / 2), left: vp_w - (offset.width + (ciw.width / 2)), zIndex: 9999});
                    cl.append(ci);
                    c_container.append(cl);

                    $j(document.body).append(c_container);

                    c_container.show();
                    
                    
                    calendar_open = true;
                    
                    return false;
                });
            });
            
        }
        
        $j.fn.calendar.defaults = {
            url: null,
            height: 500,
            bgColor: 'FFFFFF',
            src: 'none@none.com',
            color: ''
        }
    }) (jQuery)
    
}