/*var banners_feading_number = 0;
var banners_feading_number2 = 0;*/
var banner_state = 0;

$(document).ready(function () {

    //initiation fading banners in right column
    if ($('.banner_box_right')) {

        for (var i = 0; i <= $('.middle_line').length - 1; i++) {
            if ($('.middle_line:nth(' + i + ') > strong > span').height() < 24) {
                $('.middle_line:nth(' + i + ') > strong > span').css({ 'line-height': '42px' });
            }
            if ($('.bottom_line:nth(' + i + ') > span').height() < 24) {
                $('.bottom_line:nth(' + i + ') > span').css({ 'line-height': '46px' });
            }
            if ($('.bottom_line:nth(' + i + ') > span').height() < 34) {
                $('.bottom_line:nth(' + i + ') > span').css({ 'padding-top': '7px' });
            }
			
			if($('.banner_box_right:nth(' + i + ')').parent().hasClass('small')){
			}
        }

        $(".banner_box_right > a:nth-child(2)").hide();
        setTimeout('start_banners_fading()', 6000);
    }

    //new language menu
    $("#lang_nav_box").hover(
		function () {
		    $('#lang_nav:hidden').stop(true, true).slideDown('faster');
		},
		function () {
		    $('#lang_nav:visible').stop(true, true).slideUp('faster');
		}
	);

    $("div.nav_item_blue_01, #topBtn1, #topBtn2").hover(function () {
        $(this).find('ul:first:hidden').fadeIn('faster');
        $(this).find('ul > li.parent').mouseover(function () {
            $(this).addClass('active');
			
			if($(this).hasClass('left_alignment')){
				$(this).find('ul').css({ 'left': $(this).position().left - $(this).width() });
			}
			else {
				$(this).find('ul').css({ 'left': $(this).position().left + $(this).width() });
			}
			$(this).find('ul:first:hidden').fadeIn('faster');
        
		});
        $(this).find('ul > li.parent').mouseleave(function () {
            $(this).removeClass('active');
			$(this).find('ul:first').stop(true, true).fadeOut();
        });
    },
    function () {
        $(this).find('ul').stop(true, true).fadeOut();
    });


    // Prepare glossary linked words
    prepare_glossary_tips();

    // Prepare admin linked words
    prepare_admin_tips();

    prepare_hover_tips();

    // Register global error handler
    window.onerror = function (message, uri, line) {
        // An unplanned exception occured, it should not stop
        // the form working however, as we've caught it here.  We know
        // that typically it is a cosmetic UI error in JQuery on IE8.
        // Return true to prevent the browser from raising an exception.
        return true
    }
});

function start_banners_fading(){
	
	var state = banner_state + 1;
	if ($("#banner_line" + state + " > a:nth(0)").hasClass('active')) {
		$("#banner_line" + state + " > a:nth(0)").fadeOut(400, function() {
			
		}).removeClass('active');
		
		$("#banner_line" + state + " > a:nth(1)").fadeIn(400).addClass('active');
	} else {
		$("#banner_line" + state + " > a:nth(1)").fadeOut(400, function() {
			
		}).removeClass('active');
		
		$("#banner_line" + state + " > a:nth(0)").fadeIn(400).addClass('active');
	}

	banner_state = (banner_state + 1) % 3;
	setTimeout('start_banners_fading()', 6000);
}

function prepare_glossary_tips() {
    // Iterate over each glossary item
    $("span[class='glossary_tip']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'click' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseout' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            style: {
                border: {
                    width: 5,
                    radius: 10
                },
                padding: 10,
                textAlign: 'center',
                tip: true, // Give it a speech bubble tip with automatic corner detection
                name: 'dark' // Style it according to the preset 'cream' style
            }
        });
    });
}

function prepare_admin_tips() {
    // Iterate over each glossary item
    $("span[class='admin_tip']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'mouseover' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseout' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            style: {
                width: 400,
                border: {
                    width: 1,
                    radius: 1
                },
                padding: 10,
                textAlign: 'center',
                tip: true, // Give it a speech bubble tip with automatic corner detection
                name: 'green' // Style it according to the preset 'cream' style
            }
        });
    });
}

function prepare_hover_tips() {
	// Iterate over each glossary item
    $("span[class='glossary_tip_hover']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'mouseover' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseleave' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                },
				adjust: { 
					x: 0, 
					y: 1 
				} 
            },
			style: {
				  border: {
					 width: 3,
					 radius: 5,
					 color: '#324466'
				  },
				  classes: {
					  content: 'hover_tips_content',
					  tip: 'hover_qtip-tip'
				  },
				  background: '#212e46',
				  textAlign: 'center',
				  padding: 3,
				  textAlign: 'center',
				  tip: 'bottomMiddle',
				  name: 'dark' // Inherit the rest of the attributes from the preset dark style
		   	}
        });
    });
}

function onclick_livesupport(){
    // Open new window for live support
    window.open('https://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=4228439601009322029&url=' + escape(document.location.href), 'Chat1523280939266028415', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

function faq_toggle(id){
    $("p[id$='i_A_" + id + "']").toggle("slow");
    
    // Prevent anchor being followed
    return(false);
}

function toggle(id) {
    $("[id$='" + id + "']").toggle("slow");

    // Prevent anchor being followed
    return (false);
}

function hide(id) {
    $("[id$='" + id + "']").hide();

    // Prevent anchor being followed
    return (false);
}
