// JavaScript Document
$(function () {
    if ($.browser.msie && (parseFloat($.browser.version) < 7)) {
        var oh = $("#navigation li").outerHeight() + 21;
    } else {
        var oh = $("#navigation li").outerHeight() + 5;
    }
    var ih = $("#navigation li span").height();
    $("#navigation li").mouseover(function () {
        $("span:not(.current-mark)", this).stop().animate({
            height: oh
        }, {
            queue: false,
            duration: 600,
            easing: 'easeOutBounce'
        }).addClass("norm")
    });
    $("#navigation li").mouseout(function () {
        $("span:not(.current-mark)", this).stop().animate({
            height: ih
        }, {
            queue: false,
            duration: 600,
            easing: 'easeOutBounce'
        }).removeClass("norm");
    });
    $("#navigation li a").each(function () {
        if (this.href == window.location.href.split("#")[0] || this.href == window.location.href.split("?")[0]) {
            $(this).parent("li").addClass("current")
        };
    });
    $("#navigation li ul li a").each(function () {
        if (this.href == window.location) {
            $(this).parent("li").addClass("current")
        };
        var mr = $(this).text();
        var kr = mr.replace(/ /g, "_").toLowerCase();
        $(this).attr('rel', kr);
    });
    if (!$("#navigation li").hasClass("current")) {
        //$("#navigation li:first").addClass("current");
    }
    $("#navigation").find(".current span").addClass("current-mark");
    //Hide SubLevel Menus
    $('#navigation li a:not(#navigation li ul li a)').css("background", "none")
    //$('#navigation li ul').css("visibility", "visible").hide().addClass('mar-top');
    $('#navigation li div').hide();
    $('#navigation li ul li:last-child, #navigation li ul li:last-child a').addClass('last');
    //OnHover Show SubLevel Menus
    $('#navigation li').hover(
    //OnHover
    function () {
        $('#navigation li').not($('div', this)).stop();
        // Show Hoved Menu
        $('div', this).stop(true, true).animate({
            top: '-=10',
            height: 'toggle',
            opacity: 'toggle'
        }, 400, 'easeOutQuad');
    },
    //OnOut
    function () {
        // Hide Other Menus
        $('div', this).stop(true, true).animate({
            top: '+=10',
            height: 'toggle',
            opacity: 'toggle'
        }, 400, 'easeInSine');
    });
    //
    //slider	
    $('#slider').coinslider({
        width: 618,
        // width of slider panel
        height: 205,
        // height of slider panel
        spw: 7,
        // squares per width
        sph: 5,
        // squares per height
        delay: 3000,
        // delay between images in ms
        sDelay: 30,
        // delay beetwen squares in ms
        opacity: 0.8,
        // opacity of title and navigation
        titleSpeed: 500,
        // speed of title appereance in ms
        effect: '',
        // random, swirl, rain, straight
        navigation: true,
        // prev next and buttons
        links: false,
        // show images as links 
        hoverPause: false // pause on hover
    });
    // - slider
    //
    $("#news-ticker").marquee();
    $("#gallery-preview").livequery(function () {
        //$('#gallery-preview').load("gallery/latest.php");
        $(this).jCarouselLite({
            btnNext: "#nextBtn",
            btnPrev: "#prevBtn",
            visible: 1,
            easing: "easeOutQuad",
            speed: 1000,
            auto: 6000
            //vertical: true
        });
    });
    //cal-small-links
    $(".calendar-small tr td a, .img-grid li a").livequery(function () {
        $(this).addClass("pop");
    });
	
	
	
    $(".pop").livequery(function () {
        $(this).colorbox({
            width: "60%",
            height: "60%",
            iframe: true
        });
    });
	
	
	$(".img-grid li a").livequery(function () {
        $(this).addClass("pop1");
    });
	
    $(".pop1, .inLink, #page-counter fieldset p a").livequery(function () {
        $(this).colorbox({
            width: "90%",
            height: "90%",
            iframe: true
        });
    });
    //---------------------
    $('#calendar-small .cal-control a').livequery(function () {
        $(this).ajaxify({
            target: '#cal-load',
            tagToload: '#calendar-small',
            // loadHash: 'attr:rel',
            loading_txt: '<br>Please wait loading...',
            loading_img: "images/loading_02.gif"
        });
    })
    $('#calendar-full .cal-control a').livequery(function () {
        $(this).ajaxify({
            target: false,
            // tagToload: '#calendar-full',
            tagToload: {
                '#calendar-full': '#cal-load-full',
                '.details': '#event-details'
            },
            // loadHash: 'attr:rel',
            loading_target: '#cal-load-full, #event-details',
            loading_txt: '<br>Please wait loading...',
            loading_img: "images/loading_02.gif"
        });
    })
    $('#full-year-calendar a, .calendar-full a').livequery(function () {
        $(this).addClass('ajax-link');
    });
    $('#full-year-calendar').find('.event').hide().end().find('.date').click(function () {
        var k = $(this);
        var answer = $(this).next();
        if (answer.is(':visible')) {
            answer.slideUp()
            k.removeClass("current");
        } else {
            $('#full-year-calendar').find('.event').slideUp();
            $('#full-year-calendar').find('.date').removeClass("current");
            k.addClass("current");
            answer.slideDown();
        }
    });
    /*$('#full-year-calendar .event').hide().addClass('hide');
     
     $('#full-year-calendar .date').click(function(){
     
     $(this).next().slideToggle('normal');
     $(this).parent('li').removeClass('hide');
     $(this).toggleClass('current');
     });*/
    /*function scrollToDiv(id){
     $('html,body').animate({scrollTop: $(id).offset().top}, 2000);
     }*/
    function scrollToDiv(id) {
        var op = jQuery.browser.opera ? jQuery("html") : jQuery("html, body");
        op.animate({
            scrollTop: jQuery(id).offset().top
        }, 1500, 'easeOutSine');
    }
    $('.ajax-link').livequery(function () {
        $(this).ajaxify({
            target: '#event-details',
            tagToload: '.details',
            // loadHash: 'attr:rel',
            loading_txt: '<br>Please wait loading...',
            loading_img: "images/loading_02.gif",
            onStart: function (options) {
                scrollToDiv("#event-details");
            }
        });
    })
    //tabs
    $('#tabsHd li:last-child, #tabsHd li:last-child a').addClass("remove-bdr");
    jQuery(".tab:not(:first)").hide();
    jQuery(".tab:first").show();
    $('.etabs li:first a').addClass("active");
    jQuery(".etabs a").click(function () {
        stringref = jQuery(this).attr("href").split('#')[1];
        elem = $(".etabs a");
        if (elem.is(".active")) {
            jQuery(".etabs a").removeClass("active");
        }
        jQuery(this).addClass("active");
        jQuery('.tab:not(#' + stringref + ')').hide();
        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            jQuery('.tab#' + stringref).show();
        }
        else jQuery('.tab#' + stringref).fadeIn();
        return false;
    });
    //--------------------
    /*$("a[href^='#']:not('#tabsHd a')")
     .each(function()
     { 
     this.href = this.href.replace('#', 
     "");
     });*/
    //-------------------
    $('#sb-nav li').has('ul').addClass('open');
    $('#sb-nav li ul').hide();
    $('#sb-nav li:has(ul) a').mouseover(
    function () {
        $(this).not('#sb-nav li ul li a').toggleClass('dd-link');
        $(this).next().slideToggle('normal');
        $(this).parent().not('#sb-nav li ul li').toggleClass('open').toggleClass('opened');
    });
    //
    $("#sb-nav li a").livequery(function () {
        $(this).each(function () {
            var ats = $(this).attr('rel');
            var anc = window.location.href.split("#")[0] + '#' + ats;
            if (this.href == window.location || window.location == anc) {
                $(this).parent("li").addClass("current")
                $(this).addClass("active")
            };
        });
    });
    $("#sb-nav a").click(function () {
        $("#sb-nav a").removeClass("active").parent("li").removeClass("current");
        $(this).addClass("active").parent("li").addClass("current");
    });
    $('.el-table').livequery(function () {
        $('tr:odd').addClass('odd');
        $('tr:even').addClass('even');
        $('td:last-child').addClass('tc');
        $('th:first-child').addClass('tl');
    });
    // eqc
    // $('.cont-area, .cont').addClass('eqc');
    /*  (function ($) {
     $.fn.eqc = function () {
     var content='.inner';	
     var sidebar='.cont';		
     var contentH = $(content).height();	
     var sidebarH = $(sidebar).height();	
     
     if(contentH > sidebarH){	
     $(sidebar).css('height',contentH)	
     }
     
     else{
     $(content).css('height',sidebarH)	
     } 
     
     }
     })(jQuery);
     
     
     $().eqc();
     
     $('.cont-area').bind( 'resize', function(e) {
     
     var h = $('.cont-area').height() ;
     $('.cont').animate({ height: h });
     
     });
     
     */
    // eqc
    $('#sb-nav li a:not(.base)').livequery(function () {
        $(this).ajaxify({
            target: '.cont-area',
            tagToload: '.inner',
            loadHash: 'attr:rel',
            loading_txt: '<br>Please wait loading...',
            loading_img: "images/loading_02.gif",
            onSuccess: function (op) {
                $("#navigation li ul li").removeClass("current")
                $("#navigation li ul li a").each(function () {
                    var ats = $(this).attr('rel');
                    var anc = window.location.href.split("#")[0] + '#' + ats;
                    if (window.location == anc) {
                        $(this).parent("li").addClass("current")
                    };
                });
            },
            onStart: function (op) {
                $.validationEngine.closePrompt(".formError", true);
            }
        });
    });
    $("h2:not('.n-tab-holder h2')").livequery(function () {
        $(this).each(function () {
            var hdval = $(this).text();
            var hdf = hdval.replace(/ /g, "_").toLowerCase();
            $(this).attr('id', hdf);
        });
    })
    $("#contact-form").livequery(function () {
        $(this).validationEngine({
            inlineValidation: true
        });
    });
    $("#reset").livequery(function () {
        $(this).click(function () {
            $.validationEngine.closePrompt(".formError", true);
        });
    });
	$("#page-counter").livequery(function(){
	itemsPerPage = 4;	
	$(this).pagination();
 	});
    // last close	
});
