$(document).ready(function() {
	$('.o').after('<span id="time"></span>');
    var loc = window.location.pathname;
    if(loc == '/'){
        $('#top .hlevel2').css('margin-top','60px');
        $('#jSlider').before('<div class="jSliderBg"><img src=/fileadmin/templates/img/white-1.png align=left height=40 width=100 ><img src=/fileadmin/templates/img/white-2.png height=40 width=100  align=right id=jSliderBgR></div>');
        $.ajax({
            url: '/services/test.php ',
            success: function(data) {
                $('#jSlider').html(data);
                $(function(){
                    $("ul#ticker01").liScroll();       
                    $('ul#ticker01 img').height(40);
                    $('ul#ticker01').height(40);
                    $('ul#ticker01 img').hover(
                        function() {
                            $(this).height(100);
                            $(this).width(150);
                            $(this).parent().parent().height(100);
                        },
                        function() {
                            $(this).height(40);
                            $(this).width(60);
                            $(this).parent().parent().height(40);
                        }
                        );
                });
	
            }
        });
    }

	
    $('#menu ul li').hover(
        function() {
            $(this).addClass("active");
            $(this).find('ul').stop(true, true);
            $(this).find('ul').show();
        },
        function() {
            $(this).removeClass("active");
            $(this).find('ul').hide();
        }
        );


    var menuItem = $(".menu-item");
    var submenuItems = $(".submenu-items");
    menuItem.mouseover(function() {
        menuItem.removeClass('active-over');
        submenuItems.css("left", "-10000px");
        $(this).addClass('active-over');
        $(this).find(".submenu-items").css("left", "0");
    });

    $("a.active").next(".submenu-items").css("left", "0");

    var drop = $(".drop");

    drop.live('click', function() {
        $('.dropUL').hide();
        var obj = $(this);
        obj.next().toggle();
        return false;
    });

    $('#mark a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=model&cID=' + obj.attr('title'),
            success : function(html) {
                $("#model").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
        $('#model a').parent().parent().prev().text('Модель');
        $('#year a').parent().parent().prev().text('Год выпуска');
    });

    $('#model a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=year&cID=' + obj.attr('title'),
            success : function(html) {
                $("#year").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
        obj.attr('name', 'active');
        $('#year a').parent().parent().prev().text('Год выпуска');
    });

    $('#year a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        var cid = obj.attr('title');
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=body&cID=' + cid,
            success : function(html) {
                $("#body").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
        obj.attr('name', 'active');
    });

    $('#body a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=engine&cID=' + obj.attr('title'),
            success : function(html) {
                $("#engine").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
    });

    $('#engine a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=volume&cID=' + obj.attr('title'),
            success : function(html) {
                $("#volume").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
    });

    $('#volume a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=gearbox&cID=' + obj.attr('title'),
            success : function(html) {
                $("#gearbox").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
    });

    $('#gearbox a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=gear&cID=' + obj.attr('title'),
            success : function(html) {
                $("#gear").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
    });

    $('#gear a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        $.ajax({
            url : 'http://yoshida.ru/services/request.php',
            cache : false,
            data : 'id=steering&cID=' + obj.attr('title'),
            success : function(html) {
                $("#steering").html(html);
            }
        });
        obj.parent().parent().prev().text(val);
    });

    $('#steering a').live('click', function() {
        var obj = $(this);
        var val = obj.text();
        obj.parent().parent().prev().text(val);
    });


    $('*').live('click', function() {
        drop.next().hide()
    });


    $("#brokMap").click(function() {
        var obj = $(this);
        obj.next().css("display", "none");
        obj.next().toggle();
        return false;
    });
	
    $("div.hlevel1 div#auth").click(function() {
        window.location = "/html"
        return false;
    });

    var calcParam = "id=calculate";
    $("#calculate, .submit").click(function() {
        $("#popup-cont").html("загрузка данных ...");
        var cid = $("#year a[name=active]").attr('title');
        if (( cid == '') || ( cid == null)) {
            $("#popup-cont").html("<h2>Необходимо выбрать хотя бы 3 первых поля!</h2>");
            $("#popup").toggle();
        }
        else {
            $.ajax({
                url : 'http://yoshida.ru/services/request.php',
                cache : false,
                data : calcParam + '&cID=' + cid,
                success : function(html) {
                    $("#popup-cont").html(html);
                }
            });
            $("#popup").toggle();
            calcParam = "id=calculate";
        }
    });

    $("#popup-x, .dropUL, .drop").click(function() {
        $("#popup").hide();
    });


    $('.rounded, #inside-left, #inside-left div, #submenu-wrap, #popup').corner('10px');
    $('.head').corner('top 10px');
    $('.csc-firstHeader').corner('top 10px');
    $('#inside-menu li:last a').css("border", "none");

    $('#submenu-wrap, #submenu-wrap2, #submenu-wrap3').corner('10px');
    
    $("#addinp").live('click', function(){
        $('<div class="corporatmodel"><div class="modelcorp">    <label >Модель автомобиля</label>    <p><input name="models[]" class="modelscar" type="text" /></p></div><div class="modelcorp">    <label >Кол-во(шт)</label>    <p><input name="counts[]" class="counts" type="text" /></p></div><div class="modelcorp">    <label>возраст (от-до)</label>    <p><input name="oldfrom[]" class="old" type="text" /><input name="oldto[]" class="old"  type="text" /></p></div><a href="#" class="delete" onclick="return false;"><i>удалить</i></a></div>').appendTo("#inputsmodel");
    })
    $(".delete").live('click', function(){
        $(this).parent().remove();
    })
    

})
;
        
        
function screenSize() {
    var w, h; 
    w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
    h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
    return {
        w:w,
        h:h
    };
}
	
	
function Clock_ms() {
 
    /* Настройки внешнего вида */
    var c_h  =      '#FFFFFF';      // Цвет часов
    var c_m  =      '#FFFFFF';  // Цвет минут
    var c_s  =      '#FFFFFF';  // Цвет секунд
    var c_ms =      '#FFFFFF';  // Цвет миллисекунд
    var sep  =      '#FFFFFF';  // Цвет разделителей
    /* ======== /END ======== */
 
    /* Для нормальной работы скрипта ниже лучше ничего не менять! */
    var data = new Date();
    var hour = data.getHours();
    var min = data.getMinutes();
    var sec = data.getSeconds();
    var ms = (data.getTime()/10).toFixed(0).substr(10);
    if (hour<10) {hour = '0' + hour};
    if (min<10) {min = '0' + min};
    if (sec<10) {sec = '0' + sec};
    var time = '<span style="color:'+c_h+'">'+hour+'</span>'+'<span style="color:'+sep+'"> : </span>'+'<span style="color:'+c_m+'">'+min+'</span>'+'<span style="color:'+sep+'"> : </span>'+'<span style="color:'+c_s+'">' +sec +'</span>'+'<span style="color:'+sep+'"> : </span>'+'<span style="color:'+c_ms+'">'+ms+'</span>';
    document.getElementById('time').innerHTML = time;
    setTimeout("Clock_ms()",1);
    /* ========================== /END ========================== */
}
onload = Clock_ms;

	
	
	
	
	
/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2 (30-MARCH-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */


jQuery.fn.liScroll = function(settings) {
    settings = jQuery.extend({
        travelocity: 0.07
    }, settings);
    return this.each(function(){
        var $strip = jQuery(this);
        $strip.addClass("newsticker")
        var stripWidth = 0;
        var $mask = $strip.wrap("<div class='mask'></div>");
        var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
        var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width
        $strip.find("li").each(function(i){
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
        });
        $strip.width(stripWidth);
        var totalTravel = stripWidth+containerWidth;
        var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye
        function scrollnews(spazio, tempo){
            $strip.animate({
                left: '-='+ spazio
            }, tempo, "linear", function(){
                $strip.css("left", containerWidth);
                scrollnews(totalTravel, defTiming);
            });
        }
        scrollnews(totalTravel, defTiming);
        $strip.hover(function(){
            jQuery(this).stop();
        },
        function(){
            var offset = jQuery(this).offset();
            var residualSpace = offset.left + stripWidth;
            var residualTime = residualSpace/settings.travelocity;
            scrollnews(residualSpace, residualTime);
        });
    });
};
