$(document).ready(function(){	               
	var jplaylist_v = new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1",
		preload: 'auto'		
	}, [
	    {
			title:"first",
			artist:"first",
			mp3:"http://www.umi.swedmebel.ru/js/player/muz/03.mp3",
			oga:"http://www.umi.swedmebel.ru/js/player/muz/03.ogg"

		},
		{
			title:"second",
			artist:"second",
			mp3:"http://www.umi.swedmebel.ru/js/player/muz/02.mp3",
			oga:"http://www.umi.swedmebel.ru/js/player/muz/02.ogg"

		},				
		{
			title:"third",
			artist:"third",
			mp3:"http://www.umi.swedmebel.ru/js/player/muz/04.mp3",
			oga:"http://www.umi.swedmebel.ru/js/player/muz/04.ogg"

		},
		{
			title:"fourth",
			artist:"fourth",
			mp3:"http://www.umi.swedmebel.ru/js/player/muz/05.mp3",
			oga:"http://www.umi.swedmebel.ru/js/player/muz/05.ogg"

		},
		{
			title:"fifth",
			artist:"fifth",
			mp3:"http://www.umi.swedmebel.ru/js/player/muz/01.mp3",
			ga:"http://www.umi.swedmebel.ru/js/player/muz/01.ogg"

		}
	], {
		swfPath: "js",
		supplied: "ogv, oga, mp3"
	});
    $(".jp-volume-bar").hide();
	    $("#right .jp-controls-holder").hover(
	           function () {
	               $("#right .jp-volume-bar").show();
	               $("#right .jp-volume-bar").stop(true, true).fadeIn(500);
	           },
	           function () {
	               $("#right .jp-volume-bar").stop(true, true).fadeOut(500);
	           }
           );
           
    var pl_time;
    var playing;                
    var song_current; 
    var link;
    var bool;    
	    
    pl_time = $.cookie('pl_time');
    playing = $.cookie('playing');       
    song_current = $.cookie('song_current');
    
    $('#copy').append('<p id="update_p" style=\"color:white; font-size: 12px; font-family: Helvetica;\"></p>');    
    /*function update_p(){
    	$('#update_p').text(pl_time + '  ' + playing + '  ' + song_current);
	}*/
	function update_cookie(){
		$.cookie('pl_time', null,{expires: 7,path: '/'});			
		$.cookie('pl_time', pl_time,{expires: 7,path: '/'});
		$.cookie('playing', null,{expires: 7,path: '/'});
		$.cookie('playing', playing,{expires: 7,path: '/'});
		$.cookie('song_current', null,{expires: 7,path: '/'});		
		$.cookie('song_current',song_current,{expires: 7,path: '/'});		
	}            
	$(".jp-play").click( function(){
		playing = 1;
	});		
	
	$("#jquery_jplayer_1").bind($.jPlayer.event.ready, function(event) {
		if (playing == 1){
			jplaylist_v.play(song_current);
			/*update_p();*/
		}
		else{
			// hui
		}					
	});		    	
               
	$("#jquery_jplayer_1").bind($.jPlayer.event.play, function(event) {						
		$("#jquery_jplayer_1").jPlayer("playHead", pl_time);				
		$("#jquery_jplayer_1").bind($.jPlayer.event.timeupdate, function(event) {
			pl_time = $("#jquery_jplayer_1").data("jPlayer").status.currentPercentRelative;
			if ( pl_time > 99.5 ){
				pl_time = 0;
				song_current++;
				if ( song_current == 5){
					song_current = 0;	
				}			
				jplaylist_v.play(song_current);	
			}
			/*update_p();	*/													
		});
	});
	$(".jp-stop").click( function(){
				playing = null;
				song_current = 0;
				pl_time = 0;
				$.cookie('pl_time', null,{expires: 7,path: '/'});
				$.cookie('song_current', null,{expires: 7,path: '/'});
				$.cookie('playing', null,{expires: 7,path: '/'});					
			});		
	/*		
	$("#jquery_jplayer_1").bind($.jPlayer.event.ended, function(event) {	
			
		song_current++;				
		jplaylist_v.play(song_current);
							
	});*/
	       
	$(window).unload(function() {		
		update_cookie();												
	});			
    $("a").click( function(){
		update_cookie(); 										
	});
	
    $("li#b2 > a").attr("href", "http://swedmebel.ru/kollekcii/modulnie_sistemy/");
    $(".model").hover(
           function () {
               $(".jp-volume-bar").show();
           },
           function () {
               $(".jp-volume-bar").stop(true, true).fadeOut(500);
           }
           );
           
           
/* HEIGHTS ---------------------------------------------------------------------------*/

                    var height;   										             	 
					height = $(window).height();
					var a = 0;var b;b = 660; var c =0; var top_jp; var q = 0;
					function add_butt(){
						if ((height < b) && (a < 1)){
							$('.slider-wrapper, #heading, #models, #news_b #heading h1, #stocks_b #heading h1').before('<div id=\"left_buttons\" style=\"position:absolute;\"><a id=\"home_media\" href=\"/\"></a><div id=\"but1\"><a class=\"rotate_this\" href=\"/novosti_2012\"></a></div><div id=\"but2\"><a class=\"rotate_this\" href=\"/akcii\" ></a></div>');
							a = 2;							
					  	}
					}
					function add_player(){
						if ((height < b) && (c < 1)){				
							if (!q){
								top_jp = $('#jp_container_1');
								q = !q;
							}		
							$('.slider-wrapper, #heading, #models, #news_b #heading h1, #stocks_b #heading h1').before(top_jp);														
							$('.play-pause').prependTo('ul.jp-controls');
								
								
							/*
							$('.jp-play').css({'width':'5px', 'position' : 'absolute'});
							$('.jp-controls-holder, .jp-interface ul.jp-controls').css({'width': '20px'});
							$('.jp-interface ul.jp-controls,.jp-controls-holder').css({'height': '120px'});
							$('.palka_li, #mute_li').css({'display': 'none'});
							$('.jp-stop').css({'margin-top':'30px'});
							$('.jp-controls-holder').css({'padding-top': '10px'});*/																										
					  		c = 2;
					  	}
					}
					function remove_player(){
						if ((height > b) && (c > 1)){				
							$(top_jp).prependTo('#right');
							$('.play-pause').appendTo('.jp-controls');			
							c = 0;
								
							
						}
					}
					add_butt();
					add_player();
					$(window).resize(function() {                                        	                    	                    							                    
					  	height = $(window).height();
					  	add_butt();
					  	add_player();
					  	remove_player();					  	
					});
        


});




