function SwitchTopstory(topStory, mouseOver) {
    var topStoryObject = $('#' + topStory);
    var actualStory = $(".header-left-links a.actual");
    if (!topStoryObject.hasClass('actual')) {
        actualStory.removeClass('actual');
        topStoryObject.addClass('actual');
    }
    if (mouseOver) {
        actualStory.stop().animate(
        {
            color: '#3b3b3b',
            backgroundPosition: '220px -30px'
        }, 165);
        topStoryObject.css({
            color: '#3b3b3b',
            backgroundPosition: '220px -30px'
        })
        .stop().animate(
        {
            color: '#fff',
            backgroundPosition: '0 -30px'
        }, 170);
    }
    if (!$('#topstories .show').hasClass(topStory)) {
        $('#topstories .show')
        .stop().animate(
        {
            backgroundPosition: '4px -10px',
            opacity: 0
        }, 85, function() {
            $(this)
            .removeClass('show')
            .addClass('hide')
            .css({
                backgroundPosition: '4px 5px',
                opacity: 1
            });
            if ($(this).find('.topstory-info-line')) {
                $(this)
                .find('.topstory-info-line').first()
                .stop().animate(
                {
                    opacity: 0
                }, 170);
            }
            if ($('#topstories .' + topStory).find('.topstory-info-line')) {
                $('#topstories .' + topStory)
                .find('.topstory-info-line').first()
                .css({
                    opacity: 0
                });
            }
            $('#topstories .' + topStory)
            .css({
                backgroundPosition: '4px 10px',
                opacity: 0
            })
            .removeClass('hide')
            .addClass('show')
            .stop().animate(
            {
                backgroundPosition: '4px 5px',
                opacity: 1
            }, 85, function() {
                if ($('#topstories .' + topStory).find('.topstory-info-line')) {
                    $('#topstories .' + topStory)
                    .find('.topstory-info-line').first()
                    .stop().animate(
                    {
                        opacity: 1
                    }, 170);
                }
            });
        });
        $('#topstory-numbers .selected').removeClass('selected');
        $('#topstory-numbers .' + topStory).addClass('selected');
    }
}

function BindLogoListArrowUp() {
    $('.header-right-logo-list-arrow-up').bind('click', function() {
        ScrollLogosUp(250);
    });
}

function BindLogoListArrowDown() {
    $('.header-right-logo-list-arrow-down').bind('click', function() {
        ScrollLogosDown(250);
    });
}

function ScrollLogosUp(speed) {
    $('.header-right-logo-list-arrow-up').unbind('click');
    var logoList = $('#logo-list');
    var firstLogo = logoList.children().first();
    firstLogo
    .stop().animate(
    {
        height: 0
    }, speed)
    .children().first()
    .stop().animate(
    {
        backgroundPosition: '50% -44px'
    }, speed, function() {
        $(this).css({
            backgroundPosition: '50% 0'
        });
    });
    firstLogo
    .next().next().next()
    .stop().animate(
    {
        height: '44px'
    }, speed, function() {
        logoList.append('<div class="logo-container">' + firstLogo.html() + '</div>');
        firstLogo.remove();
        BindLogoListArrowUp();
    });
}

function ScrollLogosDown(speed) {
    $('.header-right-logo-list-arrow-down').unbind('click');
    var logoList = $('#logo-list');
    var lastLogo = logoList.children().last();
    var thirdLogo = logoList.children().first().next().next();
    logoList.prepend('<div class="logo-container" style="height: 0">' + lastLogo.html() + '</div>');
    var firstLogo = logoList.children().first();
    thirdLogo
    .stop().animate(
    {
        height: 0
    }, speed)
    .children().first()
    .stop().animate(
    {
        backgroundPosition: '50% 0'
    }, speed, function() {
        $(this).css({
            backgroundPosition: '50% 0'
        });
    });
    firstLogo.children().first()
    .css({
        backgroundPosition: '50% -44px'
    })
    .stop().animate(
    {
        backgroundPosition: '50% 0'
    }, speed);
    firstLogo
    .stop().animate(
    {
        height: '44px'
    }, speed, function() {
        lastLogo.remove();
        BindLogoListArrowDown();
    });
}

function RotateTopstory() {
    var actualStory = $("#topstory-items .actual");
    if(actualStory.parent().next().text() != "") {
        SwitchTopstory(actualStory.parent().next().children().first().attr('id'), false);
    }
    else {
        SwitchTopstory($("#topstory-items a").first().attr('id'), false);
    }
}

function TimedEvents() {
    if($("#topstories")) {
        $(document).everyTime(4000, 'topstory', function() {
            RotateTopstory();
        });
    }
    if($("#logo-list")) {
        $(document).everyTime(3000, 'logolist', function() {
            ScrollLogosUp(1000);
        });
    }
    $('#dropdown').hover(
        function () {
            //change the background of parent menu
            $('#dropdown li a.parent').addClass('hover');
            //display the submenu
            $('#dropdown ul.children').show();
        },
        function () {
            //change the background of parent menu
            $('#dropdown li a.parent').removeClass('hover');
            //display the submenu
            $('#dropdown ul.children').hide();
        }
        );
}

$(function() {

    /* main menu slide */

    $("#menu-fooldal")
    .css({
        backgroundPosition: '0 31px'
    })
    .mouseover(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '0 0'
        }, 100);
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '0 31px'
        }, 100);
    });
    $("#menu-megoldasaink")
    .css({
        backgroundPosition: '-97px 31px'
    })
    .mouseover(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-97px 0'
        }, 150);
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-97px 31px'
        }, 150);
    });
    $("#menu-ugyfeleink")
    .css({
        backgroundPosition: '-239px 31px'
    })
    .mouseover(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-239px 0'
        }, 150);
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-239px 31px'
        }, 150);
    });
    $("#menu-magunkrol")
    .css({
        backgroundPosition: '-351px 31px'
    })
    .mouseover(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-351px 0'
        }, 150);
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-351px 31px'
        }, 150);
    });
    $("#menu-kapcsolat")
    .css({
        backgroundPosition: '-471px 31px'
    })
    .mouseover(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-471px 0'
        }, 150);
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            backgroundPosition: '-471px 31px'
        }, 150);
    });

    /* left box tab slide */

    $("li.content-left-box-tab-iphone, li.content-left-box-tab-blackberry, li.content-left-box-tab-android")
    .click(function(){
        $(".show").addClass("hide");
        $(".show").removeClass("show");
        $(".content-left-box-tabs li a").css({backgroundPosition: '0 -55px'});
        if ($(this).hasClass("content-left-box-tab-android")) {
            $(this).children().css({backgroundPosition: '0 0'});
            $("div.content-left-box-tab-android").removeClass("hide");
            $("div.content-left-box-tab-android").addClass("show");
        } else if ($(this).hasClass("content-left-box-tab-blackberry")) {
            $(this).children().css({backgroundPosition: '0 0'});
            $("div.content-left-box-tab-blackberry").removeClass("hide");
            $("div.content-left-box-tab-blackberry").addClass("show");
        } else if ($(this).hasClass("content-left-box-tab-iphone")) {
            $(this).children().css({backgroundPosition: '0 0'});
            $("div.content-left-box-tab-iphone").removeClass("hide");
            $("div.content-left-box-tab-iphone").addClass("show");
        }
        console.log($(this).parent());
    });

    /* header left links fade */

    $(".header-left-links-subpage .header-left-content a")
    .mouseover(function() {
        $(this).stop().animate(
        {
            color: '#fff',
            backgroundColor: '#474747'
        }, 'fast');
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            color: '#68d0dc',
            backgroundColor: '#3b3b3b'
        }, 'fast');
    });

    /* content left links fade */

    $(".content-left-box-blue a")
    .mouseover(function() {
        $(this).stop().animate(
        {
            color: '#fff',
            backgroundColor: '#00324f'
        }, 'fast');
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            color: '#68d0dc',
            backgroundColor: '#002a43'
        }, 'fast');
    });

    $(".content-left-box-black a")
    .mouseover(function() {
        $(this).stop().animate(
        {
            color: '#fff',
            backgroundColor: '#2e2e2e'
        }, 'fast');
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            color: '#68d0dc',
            backgroundColor: '#212121'
        }, 'fast');
    });

    /* content link list fade */

    $("#content-center-column .link-list a, .content-column-right .link-list a")
    .mouseover(function() {
        $(this).stop().animate(
        {
            color: '#fff',
            backgroundColor: '#393939'
        }, 'fast');
    })
    .mouseout(function() {
        $(this).stop().animate(
        {
            color: '#002a43',
            backgroundColor: '#f4f4f4'
        }, 'fast');
    });

    /* header left links slide, switches topstory */

    $(".header-left-links a").hover(
        function() {
            SwitchTopstory($(this).attr('id'), true);
        },
        function() {
            $(this).stop().animate(
            {
                color: '#3b3b3b',
                backgroundPosition: '220px -30px'
            }, 165);
        });
	
    /* client list slide */

    if ($("#client-list")) {
        var clientList = $("#client-list");
        $("#client-list-next").click(function() {
            var clientShow = clientList.find('.show').first();
            if (clientShow.next().text() != "") {
                clientShow
                .stop().animate(
                {
                    marginLeft: '-5px',
                    opacity: 0
                }, 165, function() {
                    $(this)
                    .removeClass('show')
                    .addClass('hide')
                    .css({
                        marginLeft: 0,
                        opacity: 1
                    })
                    .next()
                    .css({
                        marginLeft: '5px',
                        opacity: 0
                    })
                    .removeClass('hide')
                    .addClass('show')
                    .stop().animate(
                    {
                        marginLeft: 0,
                        opacity: 1
                    }, 165
                    );
                });
            }
            else {
                clientShow
                .stop().animate(
                {
                    marginLeft: '-5px',
                    opacity: 0
                }, 165, function() {
                    $(this)
                    .removeClass('show')
                    .addClass('hide')
                    .css({
                        marginLeft: 0,
                        opacity: 1
                    })
                    .parent().children().first()
                    .css({
                        marginLeft: '5px',
                        opacity: 0
                    })
                    .removeClass('hide')
                    .addClass('show')
                    .stop().animate(
                    {
                        marginLeft: 0,
                        opacity: 1
                    }, 165
                    );
                })
            }
        });
        $("#client-list-prev").click(function() {
            var clientShow = clientList.find('.show').first();
            if (clientShow.prev().text() != "") {
                clientShow
                .stop().animate(
                {
                    marginLeft: '5px',
                    opacity: 0
                }, 165, function() {
                    $(this)
                    .removeClass('show')
                    .addClass('hide')
                    .css({
                        marginLeft: 0,
                        opacity: 1
                    })
                    .prev()
                    .css({
                        marginLeft: '-5px',
                        opacity: 0
                    })
                    .removeClass('hide')
                    .addClass('show')
                    .stop().animate(
                    {
                        marginLeft: 0,
                        opacity: 1
                    }, 165
                    );
                });
            }
            else {
                clientShow
                .stop().animate(
                {
                    marginLeft: '5px',
                    opacity: 0
                }, 165, function() {
                    $(this)
                    .removeClass('show')
                    .addClass('hide')
                    .css({
                        marginLeft: 0,
                        opacity: 1
                    })
                    .parent().children().last()
                    .css({
                        marginLeft: '-5px',
                        opacity: 0
                    })
                    .removeClass('hide')
                    .addClass('show')
                    .stop().animate(
                    {
                        marginLeft: 0,
                        opacity: 1
                    }, 165
                    );
                });
            }
        });
    }

    /* logo list up/down */

    /*	if ($("#logo-list")) {
		$('.header-right-logo-list-arrow-up').click(function() {
		  ScrollLogosUp(250);
		});
		$('.header-right-logo-list-arrow-down').click(function() {
		  ScrollLogosDown(250);
		});
	}*/

    if ($("#logo-list")) {
        BindLogoListArrowUp();
        BindLogoListArrowDown();
    }

    /* stop topstory on hover */

    $("#topstory-items a, #topstories").hover(function() {
        $(document).stopTime('topstory');
    },
    function() {
        $(document).everyTime(4000, 'topstory', function() {
            RotateTopstory();
        });
    });

    $(".header-right-logo-list").hover(function() {
        $(document).stopTime('logolist');
    },
    function() {
        $(document).everyTime(3000, 'logolist', function() {
            ScrollLogosUp(1000);
        });
    });

    /* init */

    if ($("#logo-list")) {
        $('#logo-list').find('.hide')
        .css({
            height: 0
        })
        .removeClass('hide')
        .addClass('show');
    }

    /* start timed events on document load */

    $(document).ready(function() {
        TimedEvents();
          $('a.lightbox').lightBox();
    });
});

