    google.load("swfobject", "2.1");


	function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("ytPlayer");
        // This causes the updatePlayerInfo function to be called every 250ms to
        // get fresh data from the player
        setInterval(updatePlayerInfo, 250);
        updatePlayerInfo();
        ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
        ytplayer.addEventListener("onError", "onPlayerError");
        //Load an initial video into the player
        ytplayer.cueVideoById("ylLzyHk54Z0");
      }

      // The "main method" of this sample. Called when someone clicks "Run".
      function loadPlayer(id) {
        // Lets Flash from another domain call JavaScript
        var params = { allowScriptAccess: "always" };
        // The element id of the Flash embed
        var atts = { id: "ytPlayer" };
        // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
        swfobject.embedSWF("http://www.youtube.com/apiplayer?" +id+
                           "&enablejsapi=1&playerapiid=player1",
                           "videolayer", "640", "480", "8", null, null, params, atts);



      }
     //function _run() {
     //   loadPlayer();
     // }
     // google.setOnLoadCallback(_run);















	$(document).ready(function() {

    //so = new SWFObject('/html/player.swf','mpl','640','480','9');


 	$('a.video').click(function(){

		//so.addParam('allowfullscreen','true');
		//so.addParam('allowscriptaccess','always');
		//so.addParam('wmode','opaque');
		//so.addVariable('file',this.href);
		//so.addVariable('movie',this.href);
		//so.addVariable('file','http://www.youtube.com/watch?v=5GFPJ-_QA-s');
		//so.addVariable('autostart','true');
		//so.write('videolayer');

       id = this.href.replace('http://www.youtube.com/watch?v=','');
       //loadPlayer(id);
       //ytplayer.playVideo();
       $('#videolayer').html('<div style="height: 450px;position: absolute;width: 640px;"></div><object width="640" height="480" id="obj";><param name="movie" value="http://www.youtube.com/v/'+id+'?hl=ru&fs=1&autoplay=1"></param><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/'+id+'?hl=ru&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="480" wmode="transparent"></embed></object>');
       //$('#videolayer').html('<div style="height: 450px;position: absolute;width: 640px;"></div><object width="640" height="480" id="obj";><param name="movie" value="http://www.youtube.com/v/'+id+'?hl=ru&fs=1&autoplay=1"></param><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+id+'?hl=ru&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="480" wmode="transparent"></embed></object>');

       $('#obj').click(function(){alert('123');return false;})

		$('#videotitle h1').text(this.title);
		//$('a.close').show();
		$('#videotitle').show();

		$('#news').hide();
		$('#videogal').addClass('right');

 		return false; 	})
    $('a.close').click(function(){    	$('#videotitle').hide();
    	$('#videolayer').empty();
    	return false;
    })






      	$('#calc input').keyup(function(){
            btotal = 0
			$('#calc table').each(function(){
				id = this.id
				total = 0
				$(this).find('input').each(function(){

					if($(this).val())						{						sum = parseInt($(this).val())*parseInt($(this).parents('tr').find('td:eq(2)').html().replace('р.','').replace(/ /g,'')) ;
						$(this).parents('tr').find('td:eq(4)').text(sum+' руб.');
						total = total + sum;
						}


				})
				$('#'+id.replace('_','')+' b').text(total);
				btotal = btotal+total;			})
            $('#total b').text(btotal);

		})


















        $('div.menu_item').each(function(){         $(this).prepend('<div class="open"></div>');
         $(this).append('<div class="close"></div>');        })

 		bookmark = function(){alert(this.id)}

       	var host = 'http://'+location.host
    	var furl = location.href.replace(host,"")
        $('div.page a').each(function(){    		var href = this.href.replace(host,"")
    		if (href == furl)
    			{    			id = $(this).parent().attr('id');
    			id = id.replace("page_","");
    			$('div.current').removeClass('current');
    			$('#bm'+id).parent('div').addClass('current');
    			$('div.page.v').removeClass('v');
    			$('#page_'+id).addClass('v');
    			//break;
    			}        })

        $("a[href$=jpeg],a[href$=jpg],a[href$=JPEG],a[href$=JPG],a[href$=gif],a[href$=png]").fancybox();
		$("#fsend").val(1)

		$("#feedback").submit(function(){
    	var form = this;
    	$.post("/", $(form).serialize(),function(responseText){
			if (responseText == "-1")
				alert("Неизвестная ошибка. Попробуйте связаться с нами по телефону")
			else if (responseText == "0")
				alert("Пожалуйста, заполните все поля, отмеченные *")
			else if (responseText == "1")
				{
				$(form).prepend('<p style="color:red;font-weight:bold">Сообщение отправлено</p>')
				//alert("Сообщение отправлено")
				$("#feedback").each(function(){this.reset();});


				}
			else alert("Неизвестная ошибка. Попробуйте связаться с нами по телефону."+responseText )
		});
		return false;
    })


		$('a.bookmark').click(function(){			id = this.id.replace('bm','');
			$('#page_'+id).animate({"left": "-=398px"}, "slow");
			$('div.page').removeClass('v');
			$('#page_'+id).addClass('v');
			//$('#page_'+id).toggle();
			$('div.current').removeClass('current');
			$(this).parent('div').addClass('current');

			//
			//alert(id)
			return false;		})



		$('h2.h2_price').click(function(){
			$('#'+this.id+'_').toggle("fast");

			//if ($(this))
			if($(this).css('background-position') == '98% -2px')
				$(this).css('background-position','98% 100%')
				else
				$(this).css('background-position','98% -2px')
		})	});

