function UpdateMenu( linkNumber ) {
    var selectLink = $("#menu td.selected");
    var newLink = $($("#menu td").filter("[class!='link-border']").get(linkNumber));
    selectLink.removeClass( "selected" );
    newLink.addClass( "selected" );

    selectLink.children("a").children("span:first")
    .stop(false, true).animate( {
        opacity: "hide"
    }, "slow" );

    selectLink.next("td").children("div").stop(false, true).animate( {
        opacity: "hide"
    }, "slow" );

    selectLink.prev("td").children("div").stop(false, true).animate( {
        opacity: "hide"
    }, "slow" );

    newLink.children("a").children("span:first")
    .stop(false, true).animate( {
        opacity: "show"
    }, "slow" );

    newLink.next("td").children("div").stop(false, true).animate( {
        opacity: "show"
    }, "slow" );

    newLink.prev("td").children("div").stop(false, true).animate( {
        opacity: "show"
    }, "slow" );
}

function UpdateArrow( linkNumber, maxNumber ) {
    var pNumber;
    var nNumber;

    maxNumber--;

    if ( linkNumber == 0 ) {
        pNumber = maxNumber;
    }
    else {
        pNumber = linkNumber - 1;
    }

    if ( linkNumber == maxNumber ) {
        nNumber = 0;
    }
    else {
        nNumber = linkNumber + 1;
    }
    var next = $($("#menu td").filter("[class!='link-border']").get(nNumber));
    var prev = $($("#menu td").filter("[class!='link-border']").get(pNumber));

    $("a.go_left").text(prev.children("a").children("span:first").text());
    $("a.go_left").attr("href", prev.children("a").attr("href"));
    $("a.go_right").text(next.children("a").children("span:first").text());
    $("a.go_right").attr("href", next.children("a") .attr("href"));
}

function SetSlider( pageStr ) {
    var slider = new stSlider( {
        moveBlocks: $("div.page"),
        startBlock: pageStr,
        widthBlock: 1011,
        parentBlock: $("#move_page"),
        elementType: "div",
        elementClass: "page"
    } );

    $("a.go_right").click(function() {
        slider.nextSlide();
	var href = $(this).attr('href');
        UpdateMenu( slider.startBlock );
        UpdateArrow( slider.startBlock, slider.blocksLength );
	location.href = href;
	return false;
    });

    $("a.go_left").click(function() {
        slider.prevSlide();
	var href = $(this).attr('href');
        UpdateMenu( slider.startBlock );
        UpdateArrow( slider.startBlock, slider.blocksLength );
	location.href = href;
	return false;
    });

    $("table#menu a").live("click", function() {
        var number = parseInt($(this).attr("id").substr(1));
        slider.slideTo(number);
        UpdateMenu( slider.startBlock );
        UpdateArrow( slider.startBlock, slider.blocksLength );
    });

    return slider;
}

function SetStartPage( pageStr ) {
    var sldr = SetSlider( pageStr );
    UpdateMenu( pageStr );
    UpdateArrow( pageStr, sldr.blocksLength );
    LoadAnnonce(pageStr);
}

function LoadPage( pageStr ) {
    var url = document.location.href;
    var pageUrl = url.split("#")[1] + 'Deb';
    var pages = $('#move_page div.page');
    var res = -1;

    for ( i = 0; i < pages.length; i++ ) {
        if ( $(pages.get(i)).attr('id') == pageUrl ) {
            res = i;
        }
    }

    if ( res >= 0 ) {
        SetStartPage(res);
    }
    else {
        SetStartPage( pageStr );
    }
}

$("#left_flash").ready(function() {

      var fn = function() {
          var att = { data:"/flash/m1.swf", width:"700", height:"300" };
          var par = {
              menu:"true",
              quality:"high",
              wmode:"transparent",
              salign: "left"
          };
          var id = "left_flash";
          var myObject = swfobject.createSWF(att, par, id);
      };
      swfobject.addDomLoadEvent(fn);

  });

$(document).ready(function() {
    var selectLink = $("#menu td.selected");

    selectLink.children("a").children("span:first").show();
    selectLink.next("td").children("div").show();
    selectLink.prev("td").children("div").show();

    $("#menu td").filter("[class!='link-border']").hover(function() {
        if ( $(this).attr("class") != "selected"  ) {
            $(this).children("a").children("span:first")
                                 .stop(false, true).animate( {opacity: "show"}, "slow" );

            $(this).next("td").children("div").stop(false, true).animate( {opacity: "show"}, "slow" );

            $(this).prev("td").children("div").stop(false, true).animate( {opacity: "show"}, "slow" );
        }
     }, function() {
        if ( $(this).attr("class") != "selected"  ) {
            $(this).children("a").children("span:first")
                                 .stop(false, true).animate( {opacity: "hide"}, "slow" );
            if ( $(this).next("td").next("td").attr("class") != "selected" ) {
                  $(this).next("td").children("div").stop(false, true).animate( {opacity: "hide"}, "slow" );
            }
            if ( $(this).prev("td").prev("td").attr("class") != "selected" ) {
                $(this).prev("td").children("div").stop(false, true).animate( {opacity: "hide"}, "slow" );
            }
        }
    });

    $("div.wrapper_links a").hover(function() {
        var widthLink = 250 - $(this).children("span").width();
        $(this).stop(true, false).animate( {"margin-left": widthLink + "px"}, "slow" );
    }, function() {
        $(this).stop(true, false).animate( {"margin-left": 0 + "px"}, "slow" )
    });

    $(".cr_slide").jCarouselLite({
        btnNext: ".go_right_crazy",
        btnPrev: ".go_left_crazy",
        visible: 4,
        speed: 800
    });

    $(".crazy-items a").click(function() {
         $(".crazy-items a").children("img").each( function() { $(this).removeClass("select"); } );
         var largePath = $(this).attr("href");
         var largeAlt = $(this).children("img").attr("alt");
         var girlName = $(this).children("img").attr("title");

         $("#cr_image").animate( {opacity: "hide"}, "slow", function(){
             $("#cr_image").attr({src: largePath, alt: largeAlt});
             $("#cr_image").parent("a").attr("href", largePath);
             $("#cr_image").load( function() { $(this).animate( {opacity: "show"}, "slow") } );
         } );

         if ( girlName == "" ) {
            $("h3.girl_name").css( {opacity: 0} );
         }
         else {
             $("h3.girl_name").css( {opacity: 1} );
             $("h3.girl_name").text( girlName );
         }

         $(this).children("img").addClass("select");
         return false;
    });


    $(".next_crazy").click(function() {
        var selectItem = $(".cr_slide img.select").parent().parent();
        var nextItem = selectItem.next().children("a");
        var largePath = nextItem.attr("href");
        var largeAlt = nextItem.children("img").attr("alt");
        var girlName = nextItem.children("img").attr("title");

         $("#cr_image").animate( {opacity: "hide"}, "slow", function(){
             $("#cr_image").attr({src: largePath, alt: largeAlt});
             $("#cr_image").parent("a").attr("href", largePath);
             $("#cr_image").load( function() { $(this).animate( {opacity: "show"}, "slow") } );
         } );

        if ( girlName == "" ) {
            $("h3.girl_name").css( {opacity: 0} );
        }
        else {
            $("h3.girl_name").css( {opacity: 1} );
            $("h3.girl_name").text( girlName );
        }

        $(".crazy-items a").children("img").each( function() { $(this).removeClass("select"); } );
        nextItem.children("img").addClass("select");
        $('.go_right_crazy').click();
        return false;
    });

    $(".prev_crazy").click(function() {
        var selectItem = $(".cr_slide img.select").parent().parent();
        var nextItem = selectItem.prev().children("a");
        var largePath = nextItem.attr("href");
        var largeAlt = nextItem.children("img").attr("alt");
        var girlName = nextItem.children("img").attr("title");

         $("#cr_image").animate( {opacity: "hide"}, "slow", function(){
             $("#cr_image").attr({src: largePath, alt: largeAlt});
             $("#cr_image").parent("a").attr("href", largePath);
             $("#cr_image").load( function() { $(this).animate( {opacity: "show"}, "slow") } );
         } );

        if ( girlName == "" ) {
            $("h3.girl_name").css( {opacity: 0} );
        }
        else {
            $("h3.girl_name").css( {opacity: 1} );
            $("h3.girl_name").text( girlName );
        }

        $(".crazy-items a").children("img").each( function() { $(this).removeClass("select"); } );
        nextItem.children("img").addClass("select");
        $('.go_left_crazy').click();
        return false;
    });

});
