$(document).ready(function() {

	// BACKGROUND CHANGING

	/*if ($("#wrapper2").has("#subTopAnimation")) {
		$("html").css({
			"background":"url(front/images/topBg2.jpg) no-repeat center top"
		})
		$("body").css({
			"background":"url(front/images/bottomBg2.jpg) no-repeat center bottom"
		});
	}*/
	
	$("html").has("#subTopAnimation").css({
		"background":"url(front/images/topBg2.jpg) no-repeat center top"
	})
	$("body").has("#subTopAnimation").css({
		"background":"url(front/images/bottomBg2.jpg) no-repeat center bottom"
	});

    // MENU STYLES

    $("#menu ul li a").hover(function() {
        $(this).stop().animate({
            height:"40px",
            paddingTop:"15px"
        }, 200);
    }, function() {
        $(this).stop().animate({
            height:"55px",
            paddingTop:"0px"
        }, 200);
    });

    // NEWS SLIDER

    $('.homeContentLeft ul').anythingSlider({
        expand: false,
        buildArrows: true,
        buildNavigation: false,
        buildStartStop: false,
        autoPlay: true,
		pauseOnHover: false,
		autoPlayLocked: true,
		resumeDelay: 100,
        delay: 5000,
        easing:'easeInOutBack',
        animationTime:1200
    });

    // OTHER CSS TRAVESTING

    $(".catList ul li:odd").css("paddingRight", "0px");

    $(".fromWysiwyg table tr").each(function() {
        $(this).children("td").first().css({
            "border-left":"0px"
        });
        $(this).children("td").last().css({
            "border-right":"0px"
        })
    });

    $(".fromWysiwyg .miniGallery ul li a").hover(function() {
        $(this).fadeTo(300, .6);
    }, function() {
        $(this).fadeTo(300, 1);
    });

    $(".docList li").last().css("border","none");

    $(".docList li").children(".docListPic").parent().addClass("docWithPhoto");
	
	// LOGO SELECTION
	
	$("#top a.compLogo").css({
		"background":"url(front/images/poliLogo_" + $("a.currentLang").text() + ".png) no-repeat scroll left top transparent",
		"position":"relative"
	});
	
	if ($("a.currentLang").text() == 'en') {
		$("#top a.compLogo").css("left","-74px");
	}
	if ($("a.currentLang").text() == 'ru') {
		$("#top a.compLogo").css({
			"left":"-41px",
			"width":"617px"
		});
	}	

    // BANNER WIDGET

    $(".videoBox .smallSliderDots li a").click(function(e) {
        e.preventDefault();
    });

    var slideTimer,
    $ps_widget = $('.bannerWidget'),
    $ps_container = $('.smallSlider'),
    $ps_image_wrapper = $ps_container.find('.smallSliderList li'),
    $ps_nav = $ps_container.find('.smallSliderDots'),
    $links = $ps_nav.children('li'),
    current = 0,
    $link = $ps_nav.children('li').children('a');

    $ps_image_wrapper.html('<img src="' + $link.attr("href") + '" alt="" />');
    $ps_widget.find('h3').html($link.attr("title"));
    $ps_container.fadeIn(800, function() {
        $(".whiteSlide").fadeOut(800);
    });

    $links.bind('click',showImage);

    slideTimer = setTimeout(nextBaner, 5000);

    function showImage(e) {

        clearTimeout(slideTimer);

        $(".whiteSlide").css("display","block");

        var $link = $(this),
        idx = $link.index(),
        $image = $link.find('a').attr('href'),
        $title = $link.find('a').attr('title'),
        $currentImage = $ps_image_wrapper.children(),
        currentImageWidth = $currentImage.width(),
        $newImage;

        $links.eq(current).children("a").removeClass('selected');
        $link.children("a").addClass('selected');

        $ps_image_wrapper.html('<img src="' + $image + '" alt="" />').css('display', 'none').fadeIn(800);
        $newImage = $ps_image_wrapper.find('img');
        $ps_widget.find('h3').html($title);

        slideTimer = setTimeout(nextBaner, 5000);

        if($ps_image_wrapper.children().length > 1) {
            $ps_image_wrapper.children(':last').remove();
        }

        $ps_image_wrapper.prepend($newImage);
        current = idx;

        $currentImage.css("display","none");
        $newImage.css("display","block");
        $(".whiteSlide").fadeOut(800);

        e.preventDefault();
    }

    function nextBaner() {
        var slidesNumber = $('.smallSliderDots li').length;
        var currSlide = $('.smallSliderDots').find('.selected').parent();

        if (currSlide.index() + 1 == slidesNumber) {
            $('.smallSliderDots li').first().children("a").trigger("click").addClass("selected");
        }
        else {
            currSlide.next().children("a").trigger("click").addClass("selected").parent().prev().find("selected").removeClass("selected");
        }
    }	

});
