$(document).ready(function () {

    $('span.QuestionMark').tipsy({ gravity: 'se' });


    $('#OtherSitesButton a').click(function () {
        $("#OtherSitesPanel").slideToggle('slow');
        return false;
    });

    $("#HidePanelButton a").click(function () {
        $("#OtherSitesPanel").slideUp('slow');
        return false;
    });

    /* Add an extra classes */
    $('#LanguageSwitcher a:first-child').addClass("CurrentLanguage");
    $('#LanguageSwitcher a:eq(1)').addClass("OtherLanguage");



    //For Search Input
    $(".PredefinedField").each(function () {
        var default_value = this.value;
        $(this).focus(function () {
            if (this.value == default_value) {
                this.value = '';
                $(this).css('color', '#333');
            }
        });
        $(this).blur(function () {
            if (this.value == '') {
                $(this).css('color', '#97a2ab');
                this.value = default_value;
            }
        });
    });



    /*
    $("#PromoBanners ul li").each(function(){
    $(this).css({
    background: 'url('+ $(this).children().attr('src') +')',
    width:960, 
    height:700	 	
    });
    });
	
    */

    /* Start Sticky Foooter */

    /*
    stickyFooter();
    $(window).live('resize', function(event) {
    stickyFooter();
    });
	
	
    function stickyFooter()
    {	
    var wh = $(window).height(); // window height
    var bh = $('body').height(); // height of body element
		
    // if body height is smaller than window height
    if( bh < wh ) {
			
    var $top = wh - 129;
			
    $('#OuterWrapper').css('height', (wh));
    $('#Footer').css({
    left:0,
    //top: $top,
    bottom: 0,
    'position': 'absolute'
    });
	
    }
    } 
    */

    /* End Sticky Footer */


    /* Site Map Button Trigger  */
    $('#SiteMapButton a').live('click', function () {
        $('#SiteMap').slideToggle();
        return false;
    });


    /* Add .external Class to all links, with target="_blank" attribute */
    $('.SubMenuBlock ul li a[target=_blank], .SecondaryMenu ul li a[target=_blank], .BOGBanner a[target=_blank]').not(":has(img)").wrap('<span class="External" />');
    $('.SubMenuBlock a').not(":has(img)").addClass('Arrow');
    $('.SubMenuBlock h3 a').removeClass('Arrow');


    /* Navigation */
    $("#PrimaryNavigation > ul > li:has(div)").live('hover', function () {
        $(".SubMenu", this).toggle();
        return false;
    });

    $("#SecondaryNavigation > ul > li:has(div)").live('hover', function () {
        $(".SubMenu").hide();
        $(".SubMenu", this).show();
        return false;
    });

    $("#PrimaryNavigation").mouseleave(function () {
        $(".SubMenu").hide();
        return false;
    });



    $(".VideoItem a").click(function () {

        $.fancybox({
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'title': this.title,
            'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type': 'swf',
            'swf': {
                'wmode': 'transparent',
                'allowfullscreen': 'true'
            }
        });

        return false;
    });


    $("a[rel=fancybox]").fancybox({
        'padding': 0,
        'transitionIn': 'none',
        'transitionOut': 'none'
    });


    $("table.Special tr th").each(function () {
        var rows = $(this).parent().parent().children().children('th').size();
        var rowWidth = Math.floor(100 / rows);
        $(this).css('width', rowWidth + '%');
    });


    /* Management Board */
    $("div.ViewStory a").live('click', function () {
        var ViewStory = $(this).parent();
        var UserStory = $(this).parent().next();

        ViewStory.hide();
        UserStory.slideDown();

        return false;
    });


    $("div.HideStory a").live('click', function () {
        var ViewStory = $(this).parent().parent().prev();
        var UserStory = $(this).parent().parent();

        //ViewStory.remove();
        UserStory.slideUp('fast');
        ViewStory.hide().delay(500).fadeIn('fast');

        return false;
    });

    $("div.UserPhoto a").fancybox({
        'padding': 0,
        'transitionIn': 'none',
        'transitionOut': 'none'
    });



    // If #PromoBanners Element Exists
    if ($("#PromoBanners").length) {
        $("#PromoBanners").slideViewerPro({
            leftButtonInner: '',
            rightButtonInner: '',
            autoslide: true,
            //asTimer: 5000,
            buttonsWidth: 6,
            thumbsBorderWidth: 1,
            thumbsBorderColor: '#716f72',
            thumbsActiveBorderColor: '#f89827',
            galBorderWidth: 0,
            thumbs: 4,
            thumbsPercentReduction: 5
        });
    }
});

