/* 
 * A VARIUX INC. CMS
 * CREATED BY: JOHN ANDERSON
 */
jQuery.fn.jcenter = function ($wh) {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - $wh[1] ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - $wh[0] ) / 2+$(window).scrollLeft() + "px");
    return this;
}
$(function(){

    $("#main_nav ul").children().find("ul").hide();

    $("#main_nav li").hover(function(){

       $(this).children("ul").fadeIn();

    }).mouseleave(function(){

        $(this).children("ul").fadeOut();

    });

    $(".ext-link").click(function(e){

       e.preventDefault();

       var $dest    =   $(this).attr('href');

       window.open($dest,'PiratePrintingLink',"width=800,height=600,scrollbars=1,menubar=yes,toolbar=yes,status=no,resizable=yes,location=yes");

    });

    $("#content_banner").flash({

        src: 'http://www.variux.com/~piratepr/flash/home.swf',
        width: 920,
        height: 336,
        wmode: 'transparent'

    });

    $(".img-large").click(function(){

       var $src     =   $(this).attr('src');
       var $iw      =   $(window).width();
       var $ih      =   $(window).height();

       var $top     =   ($ih / 2) - (225 / 2);
       var $left    =   ($iw / 2) - (199 / 2);


        $("body").append('<div id="fader"></div><div id="image-show"><img src="' + $src + '" width="199" height="225" /></div>');

        $("#fader").css({

            'background':'#000',
            'z-index':'998',
            'position':'fixed',
            'opacity':.95,
            'width':$iw,
            'height':$ih,
            'top': 0,
            'left':0

        })


        $("#image-show").css({

            'background':'#000',
            'z-index':'999',
            'position':'fixed',
            'border': '4px solid #ccc',
            'top': $top,
            'left':$left

        })

        $("#fader,#image-show").click(function(){

            $("#fader").remove();
            $("#image-show").remove();

        });

    });
    
    var $jframe     =   function(e){
        
        var $url    =   e.attr('href');

        e.replaceWith('<iframe id="variux-jframe" src="'+ $url + '" width="516" height="325" ></iframe>');
        
    }
    
    $jframe($(".iframe"));

    $(".event-images").find('img').click(function(){

        $("#event-big-image").remove();

        var $image      =   $(this).attr('src');

        $("body").append('<img id="event-big-image" src="' + $image + '" />');

        var $dem        =   new Array($("#event-big-image").width(),$("#event-big-image").height());

        $("#event-big-image").jcenter($dem);

        $("#event-big-image").click(function(){

           $("#event-big-image").remove();

        });

    });

});

