﻿var siteDomain = "http://1062fm.co.il";
var staticDomain = "http://1062fm.co.il/static";
var forumDomain = "http://forum.1062fm.co.il";
var audioLink = escape('http://switch3.castup.net/cunet/gm.asp?ai=622&ar=LiveFlash02&curettype=1');
var videoLink = escape('http://switch3.castup.net/cunet/gm.asp?ai=622&ar=LiveFlash01&curettype=1');
var preSound = 'http://1062fm.co.il/static/mp3/preSound.mp3';
var volumePosition = 60;
var volumeBeforeMute = 60;
var isPlayerPresent = null;


$(document).ready(function(){
	$.address.change(function(event) {
		var selection = $('a[rel=address:' + event.value + ']');
		if (event.value!='/'){
			$('#main-content').load('/he'+event.value.substring(0,event.value.length) +'&' +(new Date()).getTime(),'',function (){
				$.address.title($.address.title().split(' | ')[0] ); 
				
				$('.mv-play-btn').click(function (){
					if ($(this).hasClass('current')) {
						stopVideoSpotlight(this);
						} else {
							playVideoSpotlight(this); 
							}
					return false;	
				});

$('.mv-play-btn-archive').click( function()
			{
				stopSound();
				$('#overlayVideo').append('<div id="slVideoContainer"></div>');
				$('#overlayVideo > #slVideoContainer').css('width','810px').css('height','480px');
				$('#overlayVideo > #slVideoContainer').css('display','block');
				
				changeBg(this,'item-pl-btn-stop.png');
			})
			.overlay({
			//efect: 'apple',
			onLoad: function() {
					
					var el = this.getTrigger();
					var videoClip = $(el).attr('movie') + '&curettype=1';
					var urlToPlay = '';
					$.get('/api/hole?s=' + new Date().getTime() + '&l='+escape(videoClip), function(data){
						urlToPlay = data.split(';')[0];
						
						$f('slVideoContainer',
							{
								src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', 
								wmode: 'opaque'	
							}, 
							{ 
							clip: { autostart: 'true', url: escape(urlToPlay), scaling: 'fit'},
							onLoad: function (){ this.setVolume(volumePosition); },
							//onFinish: function () { $('#slVideoContainer').remove(); stopVideoSpotlight();},
							plugins: {
								//controls: null
								} 
							}
						);
					});	

				//$('#slFeatured').show();
				//$('.videoControls').empty().hide();
				//$('.video-scroll-list ul > li').removeClass('active');
			},
			onClose: function() {
				$('#slVideoContainer').remove();
			   	stopVideoSpotlight();
			}
		});

				
				$('.item-pl-btn, .sb-play-btn, .replay-btn').click(function (){
					if ($(this).hasClass('current')) {
						stopSound(this);
						} else {
							playSound(this);
							}
					return false;	
				});

			$('#loadUpdates').click(function(){
			 	var el = $(this);
			 	
		    	$.getJSON('http://1062fm.co.il/api/updates?t='+ new Date().getTime() + '&id='+ $(this).attr('rel'), 
		    		function(data){
		    			$.each(data.items,function(i, item) {
							$('#lastUpdates').append('<li><span>'+item.info+'</span><em>'+ item.published +'</em></li>');
							
						});
					el.fadeOut("fast");	
		    		
		    		}
		    	);		
		    	return false;
		    	});
		    	
		    	
		    $('.send-mail').overlay({

				onBeforeLoad: function() {
					$('.wrap').remove();
					$('.overlay').append('<div class="wrap"></div>');
					$('.overlay').css('width','520px').css('height','580px');

					// grab wrapper element inside content
					var wrap = this.getOverlay().find(".wrap");;
					

					// load the page specified in the trigger
					wrap.load(this.getTrigger().attr("href") +'&t='+ new Date().getTime());
					$('.overlay').show();
				},

				onClose: function() {
				$('.overlay').hide();
				$('.wrap').remove();
				}

			});
			
			
			$('.send-to-friend, .send-friend, .send-to-friend-spec').overlay({

				onBeforeLoad: function() {
					$('.wrap').remove();
					$('.overlay').append('<div class="wrap"></div>');
					$('.overlay').css('width','520px').css('height','580px');

					// grab wrapper element inside content
					var wrap = this.getOverlay().find(".wrap");;
					

					// load the page specified in the trigger
					wrap.load(this.getTrigger().attr("href") +'&t='+ new Date().getTime());
					$('.overlay').show();
				},

				onClose: function() {
				$('.overlay').hide();
				$('.wrap').remove();
				}

			});
				
				$.scrollTo('#header');
/*		
		if($.browser.msie && $.browser.version == '6.0'){
		$(".b-corn, .update-tab, .navi-l-corn, .navi-r-corn, .sb-play-btn, #logo img, .tweet-link img, .set-lang, .percents, .corner-l, .corner-r, .idc-link, .overlay-bt, .title-overlay, .item-pl-btn, .mv-play-btn, .pl-play-btn, .overlay-sb, .rate, .slink-avatar, .replay-btn, .poll button").pngfix();
		$.getScript(staticDomain + '/js/libs/belated.png.js', function(){
				DD_belatedPNG.fix('.widget-archive, .sub-menu-navi, .navi-pl, .archive, .stp-vote, .home-page a img');
				menuAndCarousel();
			});
		} else { 
*/
					menuAndCarousel();		
//					}
				
				
			});
		
		// vip
		

		
		//////////////////////
				
		
		}
		else {
			$('#main-content').load('/he/main&'+ (new Date()).getTime(),'',function (){
				$('.mv-play-btn').click(function (){
					if ($(this).hasClass('current')) {
						stopVideoSpotlight(this);
						} else {
							playVideoSpotlight(this); 
							}
					return false;	
				});
				
				$('.item-pl-btn, .sb-play-btn, .replay-btn').click(function (){
					if ($(this).hasClass('current')) {
						stopSound(this);
						} else {
							playSound(this);
							}
					return false;	
				});

				$('.pl-play-btn').click(function (){
					if ($(this).hasClass('current')) {
						stopSound(this);
						} else {
							playShakes(this);
							}
					return false;	
				});
/*				
				if($.browser.msie && $.browser.version == '6.0'){
					$(".b-corn, .update-tab, .navi-l-corn, .navi-r-corn, .sb-play-btn, #logo img, .tweet-link img, .set-lang, .percents, .corner-l, .corner-r, .idc-link, .overlay-bt, .title-overlay, .item-pl-btn, .mv-play-btn, .pl-play-btn, .overlay-sb, .rate, .slink-avatar, .replay-btn, .poll button").pngfix();
					$.getScript(staticDomain + '/js/libs/belated.png.js', function(){
						DD_belatedPNG.fix('.widget-archive, .sub-menu-navi, .navi-pl, .archive, .stp-vote, .home-page a img');
						menuAndCarousel();
					});
				} else { 
*/
					menuAndCarousel();		
//					}
					
			 $('.stp-vote').click(function(){
			 	 var el = $(this);
			 	el.fadeOut("fast");
			 	el.parent().children('span.percent').fadeOut("fast");
		    	$.getJSON('http://1062fm.co.il/api/vote_he?t='+ new Date().getTime() + '&id='+ $(this).attr('id'), 
		    		function(data){
		    			$.each(data.items,function(i, item) {
							$('#'+item.shakeid).parent('div.rate').children('span.percent').html(item.percent + '%');
							
						});	
		    		
		    		
		    		$.get('http://1062fm.co.il/api/rated_he?t='+ new Date().getTime(), 
		    		function(html){
		    			$('div.statistic').html(html);
						//el.fadeIn("fast");
						el.parent().children('span.percent').fadeIn("fast");	
						});
		    		
		    		}
		    	);		
		    	

	
		    	return false;
		    	});
			
			
			$('.scroll-list ul').jScrollPane({showArrows:true, scrollbarWidth:12, scrollbarMargin: 0});
			
			$('a.up').click(function (){
				var currentTop = parseInt($('.scroll-list ul').css('top')); 
				if (currentTop<0){
					$('.scroll-list ul').animate({"top": "+=55px"}, "fast");	
				} else {
					$('.scroll-list ul').css('top','0px');	
				}
				return false;	
			});
			
			$('a.down').click(function (){
				var currentTop = parseInt($('.scroll-list ul').css('top')); 
				
				var $kids = $('.scroll-list ul').children();
      			var len = $kids.length;
				var currentBottom = len*55+(len-1)+currentTop;

				if (currentBottom>=373){
					$('.scroll-list ul').animate({"top": "-=55px"}, "fast");	
				}
					
			
				return false;	
			});
				
			});
				
		} 
	 });		
	
	
	getXMLUpdates(); 
	getTwitterUpdates();
	getSchedule();
	

    $(document).everyTime('30s', function(i) {
	 getXMLUpdates();
	});
	
	$(document).everyTime('1800s', function(i) {
	  getTwitterUpdates();
	});
	
	$(document).everyTime('300s', function(i) {
	  getSchedule();
	});
	
	function handleShowLinks(programId)
	{
		$.getJSON('http://1062fm.co.il/api/today-updates?t='+ new Date().getTime() + '&id='+ programId, 
		    		function(data){
						var items = new Array("","","","","","");
						var dates = new Array("","","");
						var uplink = new Array ("","","");
						$.each(data.items,function(i, item) {
							$('.slink-avatar').html('<img src="http://1062fm.co.il/static'+ item.photo +'" alt="" width="78" height="48" />');
							$('.slink-title').html('<a href="'+ item.uplink +'" target="_blank">'+ item.info +'</a>');
							$('.slink-date').html(item.pdate);
							
							
							items[0] = items[2];
							items[1] = items[3];
							dates[0] = dates[1];
							uplink[0] = uplink[1];
							items[2] = items[4];
							items[3] = items[5];
							dates[1] = dates[2]
							uplink[1] = uplink[2]
							items[4] = item.info;
							items[5] = item.photo;
							dates[2] = item.pdate;
							uplink[2] = item.uplink;
							
							
							$('.slink-avatar1').html('<img src="http://1062fm.co.il/static'+ items[3] +'" alt="" width="78" height="48" />');
							$('.slink-title1').html('<a href="'+ uplink[1] +'" target="_blank">'+ items[2] +'</a>');
							$('.slink-date1').html(dates[1]);
							 
							
							
							$('.slink-avatar2').html('<img src="http://1062fm.co.il/static'+ items[1] +'" alt="" width="78" height="48" />');
							$('.slink-title2').html('<a href="'+ uplink[0] +'" target="_blank">'+ items[0] +'</a>');
							$('.slink-date2').html(dates[0]);
							 

						});
						if (data.items.length>0)
						{
							
							$('#update-tab').css('background-image','url(http://1062fm.co.il/static/templates/idc/i/bg/update-tab_red.png)');
						
						/*	$('.content-slink').mouseover(function(){
									$('#right-part').css('z-index','-1');
									$('.content-slink').css('z-index','1');
									$('.content-slink').css('display','block');
									$(this).oneTime('25s', function() {
											$('#right-part').css('z-index','-1'); 
											$('.content-slink').css('display','block');  
									  	});
									return false;	
																	  }); */
							
							$('#update-tab').click(function(){
									//$('#update-tab').css('background-image','url(http://1062fm.co.il/static/templates/idc/i/bg/update-tab.png)')						
									$('#right-part').css('z-index','-1');
									$('.content-slink').css('display','block');
									
									$(this).oneTime('15s', function() {
										$('#right-part').css('z-index','1');
										$('.content-slink').css('display','none'); 

									  });
									return false;	  
								});
							
							$('#right-part').css('z-index','-1');
							$('.content-slink').css('display','block');   
								$(this).oneTime('15s', function() {
										$('#right-part').css('z-index','1');
										$('.content-slink').css('display','none');
									  });
									return false;	
						}
						else {
							hideShowLinks();
						}
		    		});		
	}


 function hideShowLinks()
 {
	 $('.content-slink').css('display','none');
	 $('#update-tab').css('background-image','url(http://1062fm.co.il/static/templates/idc/i/bg/update-tab.png)');
	 $('#update-tab').click(function(){$('.content-slink').css('display','none'); return false;});
 }
	
	function getSchedule(){
		hideShowLinks();
		var programId = 0;
		$.getJSON('http://1062fm.co.il/api/schedule_he?t='+ new Date().getTime(),
        function(data){
        	$('p.title-program').html(data.programTitle);
			$('p.with').html(' עם ' + (data.dj.length>52?data.dj.substring(0,49)+'...':data.dj)).attr('title',data.dj);
			$('div.description .indication-lang').html(data.lang);
			$('span.time-dc').html(data.dcTime);
			$('span.text-dc').html(data.dcText.length>33?data.dcText.substring(0,30)+'...':data.dcText).attr('title',data.dcText);  
		  	$('#topVideoPicture').attr('src',data.programPic);
		  	programId = data.id;
		  	if (data.livevideo!=1) {
		  		$('#playStreamVideoBtn').hide();
		  		$('#videoDisabled').remove();
		  		$('#playStreamVideoBtn').after('<div class="video-btn-gray" id="videoDisabled">Play Video</div>');
		  		
		  	} else {
		  		$('#videoDisabled').remove();
		  		$('#playStreamVideoBtn').show();
		  		
		  	}
			handleShowLinks(programId);
		  });
		
		
	}
	
	
	
	function menuAndCarousel(){
		$('ul.sf-menu').superfish();
		$('#videoScroll').jMyCarousel({
		    btnNext: $('#vslNext'),
		    btnPrev: $('#vslPrev'),
		    visible: '3',
		    eltByElt: 'false',
		    evtStart: 'mousedown',
		    evtStop: 'mouseup'
		});
	}
	function getTwitterUpdates() {
		$(".twitter").tweet({
			username: "1062fm",    
			join_text: "auto",
			count: 1,
			auto_join_text_default: "", 
			auto_join_text_ed: "",
			auto_join_text_ing: "",
			auto_join_text_reply: "",
			auto_join_text_url: "",
			loading_text: "..."
	        });
//		  $(".twitter").getPhrase({ userName: "IDCRadio", numTweets: 1, loaderId: "twitt-loader", loaderText: "…" });
    	}
	function getXMLUpdates(){
		$.get('/api/hole?s=' + new Date().getTime() + '&l=http://www.interweb.idc.ac.il/RadioIDC1.xml', function(xmlData){
			var data;
			if($.browser.msie) {
	            data = new ActiveXObject('Microsoft.XMLDOM');
	            data.async = false;
	            data.loadXML(xmlData);
		        } else {
		            data = xmlData;
		        }
		var songName = $(data).find('Current > titleName').text() + ' - ' + $(data).find('Current > artistName').text();
		$('.player-use > p').html('<span class="song-block"><strong>רצועה:</strong> '+songName+'</span>');
		});	 
   	}
	function changeBg(el, bg){
		$(el).css('background', 'url(' + staticDomain + '/templates/idc/i/bg/'+bg+') no-repeat');	
	}
	function createEl(el,id,container){
		$(document.createElement(el)).attr('id',id).appendTo(container); 	
	}
	function fixPNGButtons(){
   		$('.sb-play-btn, .item-pl-btn, .mv-play-btn, .pl-play-btn, .replay-btn').pngfix();
   	}
	function setVolume(position){
	    if ($('#audioContainer_api').attr('height')=='100%' || $('#slVideoContainer_api').attr('height')=='100%'){
		flowplayer().setVolume(position);
        }
	}
	/*
	if($.browser.msie && $.browser.version == '6.0'){
		$(".b-corn, .update-tab, .navi-l-corn, .navi-r-corn, .sb-play-btn, #logo img, .tweet-link img, .set-lang, .percents, .corner-l, .corner-r, .idc-link, .overlay-bt, .title-overlay, .item-pl-btn, .mv-play-btn, .pl-play-btn, .overlay-sb, .rate, .slink-avatar, .replay-btn, .poll button").pngfix();
		$.getScript(staticDomain + '/js/libs/belated.png.js', function(){
			DD_belatedPNG.fix('.widget-archive, .sub-menu-navi, .navi-pl, .archive, .stp-vote, .home-page a img');
			menuAndCarousel();
		});
	} else { 
		menuAndCarousel();		
		}
  	*/
	function playPreSound(el)
	{
		changeBg(el,'ajax-loader.gif');
		createEl('div','audioContainer','body');
		var divID='audioContainer';
		if(document.all)
		{
			createEl('div','audioContainerPreSound','body');
			$('#audioContainerPreSound').css('display','block').css('width','1px').css('height','1px');
			divID='audioContainerPreSound';
		}
		var audioFile = $(el).attr('rel') + '&curettype=1';
		$.get('/api/hole?s=' + new Date().getTime() + '&l='+escape(preSound), function(data){
			$f(divID, 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', { 
				clip: { autostart: 'true', url: escape(preSound)},
				onLoad: function (){try{this.setVolume(volumePosition);}catch(e){} },
				onFinish: function () { try{stopSound(el);playStreamAudioNoPreSound(el);}catch(e){}},
				plugins: {
					controls: null
					} 
				}
			);
		});	
	}
	function playStreamAudioNoPreSound(el)
	{
		var parentId = $(el).parent();
		createEl('div','loadingProgress','body');
		$('#loadingProgress').css('background','url(http://1062fm.co.il/static/images/shake/shakeLoading.gif) center no-repeat').css('position','absolute').css('top','20px').css('right','2px').css('z-index',21478344).css('width','48px').css('height','20px').css('display','none');
		stopSound();
		createEl('div','audioContainer','body');
		changeBg(el,'ajax-loader.gif');
		$(el).addClass('current');
		$.get('/api/hole?s=' + new Date().getTime() + '&l='+audioLink, function(data){
		var urlToPlay = data.split(';')[0].split('?');
		var streamer = urlToPlay[0] + '/';
		var streamURL = '_definst_%3F' + escape(urlToPlay[1]);
		try{handleFileLoading(streamURL,null,document.getElementById('loadingProgress'));}catch(e){}
		$f('audioContainer', 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', { 
		clip: { provider: 'rtmp', live: 'true', autostart: 'true', url: streamURL },
		onLoad: function (){try{this.setVolume(volumePosition);}catch(e){}setTimeout(function(){changeBg(el,'play-btn-stop.png');},2000); },
		plugins: {
		rtmp: { url: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer.rtmp-3.1.3.swf', netConnectionUrl: streamer	},
		controls: null
		} 
		}
		);
		});	
	}
	function playStreamAudio(el){
		try
		{
			playPreSound(el);
		}
		catch(e)
		{
			
		}
		finally
		{
			playStreamAudio=playStreamAudioNoPreSound;
		}
	}
	
	$('#playStreamAudioBtn').click(function (){
		this.blur();
   		if ($(this).hasClass('current')) {
			stopSound(this);
			} else {
				playStreamAudio(this);
				}
		return false;		
   	});
   	
	function playShakes(el){
		
		var parentId = $(el).parent();
		stopSound();
		createEl('div','audioContainer','#wrapper');
		$(el).addClass('current');
		
		
		if ($(el).hasClass('pl-play-btn')){
			changeBg(el,'pl-play-btn-stop.png');
			}
		
			
		$.getScript('http://1062fm.co.il/api/shake-he', function(){
				$f('audioContainer', 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', { 
				clip: { autostart: 'true'},
				playlist: conf.playlist,
				onLoad: function (){try{this.setVolume(volumePosition);}catch(e){} },
				//onFinish: function () { stopSound(el);},
				plugins: {
					controls: {playlist: true}
					} 
				}
			);
			});
	    return false;
	}
	
	function playSound(el){
	//	$('#loadingProgress').remove();
		var parentId = $(el).parent();
	//	createEl('div','loadingProgress',parentId);
		stopSound();
		createEl('div','audioContainer','#wrapper');
		$(el).addClass('current');
		
		if ($(el).hasClass('item-pl-btn')){
			changeBg(el,'item-pl-btn-stop.png');
			}
			else if ($(el).hasClass('sb-play-btn')){
				changeBg(el,'sb-stop-btn.png');
				}
				else if ($(el).hasClass('replay-btn')){
					changeBg(el,'item-pl-btn-stop.png');
					}
					else if ($(el).hasClass('play-btn')){
						changeBg(el,'play-btn-stop.png');
				    	}

// Castup update		
		var audioFile = $(el).attr('rel') + '&curettype=1';
		$.get('/api/hole?s=' + new Date().getTime() + '&l='+escape(audioFile), function(data){
			var urlToPlay = data.split(';')[0];
			$f('audioContainer', 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', { 
				clip: { autostart: 'true', url: escape(urlToPlay)},
				onLoad: function (){try{this.setVolume(volumePosition);}catch(e){} },
				onFinish: function () { stopSound(el);},
				plugins: {
					controls: null
					} 
				}
			);
		});	
// end castup update		
		/*
		$f('audioContainer', 
			{ 
				src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf'
			}, 
			{ 
			    clip: {url: audioFile},
			    onLoad: function () { $('#loadingProgress').remove(); this.setVolume(volumePosition); },
			    //canvas: { backgroundColor:'#ffffff', backgroundGradient: 'none'},
			    plugins: { controls: null}
		    }
		);
		*/
		
	    return false;
	}
	
	function stopSound(el){
		$('.item-pl-btn, .sb-play-btn, .replay-btn, .play-btn, .mv-play-btn, .mv-play-btn-archive, .prog-play, .pl-play-btn').removeClass('current');
		changeBg('.item-pl-btn, .replay-btn, .mv-play-btn, .mv-play-btn-archive','item-pl-btn.png');
		changeBg('.sb-play-btn','sb-play-btn.png');
		changeBg('.play-btn','play-btn.png');
		changeBg('.pl-play-btn','pl-play-btn.png');

		$('#audioContainer').remove();
		$('#slFeatured').show();
		$('.videoControls').empty().hide();
		$('#slVideoContainer').remove();
		$('.overlay').hide();
		$('#streamVideoContainer').remove();
		$('#topVideoPicture').show();
		return false;
	}
/*
	$('.item-pl-btn, .sb-play-btn, .replay-btn').click(function (){
		if ($(this).hasClass('current')) {
			stopSound(this);
			} else {
				playSound(this);
				}
		return false;	
	});
*/	 
	$('.volume > li').hover(function (){
		$('.volume > li').removeClass('full-volume');
		if ($(this).hasClass('full-volume')){
			$(this).removeClass('full-volume');
		}
		else {
			$(this).addClass('full-volume');
			$(this).prevAll().addClass('full-volume');
		}
	});
	
	$('.volume > li').mouseout(function() {
		$('.volume > li').removeClass('full-volume');
		switch(volumePosition){
			case 20: $('.volume > li.one').addClass('full-volume'); break;
			case 40: $('.volume > li.two').addClass('full-volume').prevAll().addClass('full-volume'); break;
			case 60: $('.volume > li.three').addClass('full-volume').prevAll().addClass('full-volume'); break;
			case 80: $('.volume > li.four').addClass('full-volume').prevAll().addClass('full-volume'); break;
			case 100: $('.volume > li.five').addClass('full-volume').prevAll().addClass('full-volume'); break;
			}
		});
		
    $('.volume > li').click(function (){
     	if ($(this).hasClass('one')){
     		volumePosition = 20;
     	}
     	else if ($(this).hasClass('two')){
     		volumePosition = 40;
     	}
     	else if ($(this).hasClass('three')){
     		volumePosition = 60;
     	}
     	else if ($(this).hasClass('four')){
     		volumePosition = 80;
     	}
     	else if ($(this).hasClass('five')){
     		volumePosition = 100;
     	}	 
	    $('.mute-btn').css('background', 'url(' + staticDomain + '/templates/idc/i/icon/volume.png) no-repeat');
	    
	    if ($('.mute-btn').hasClass('mute')){
	    	$('.mute-btn').removeClass('mute');
	    	volumeBeforeMute = volumePosition;
	    }
	    
	    setVolume(volumePosition);
	    return false;
	});
	
	
	
	$('.mute-btn').click(function (){
		if ($(this).hasClass('mute')){
			$(this).removeClass('mute');
			volumePosition = volumeBeforeMute;
			$('.mute-btn').css('background', 'url(' + staticDomain + '/templates/idc/i/icon/volume.png) no-repeat');
			$('.volume > li').trigger('mouseout');
		}
		else {
			$(this).addClass('mute');
		    volumeBeforeMute = volumePosition;
			volumePosition = 0;
			$('.mute-btn').css('background', 'url(' + staticDomain + '/templates/idc/i/icon/volume-off.png) no-repeat');
			$('.volume > li').trigger('mouseout');
		}
		setVolume(volumePosition);
		return false;	
	});	
	
	function playVideoSpotlight(el){
		stopSound();
		
		createEl('div','slVideoContainer','.main-video');
		$('.video-scroll-list ul > li').removeClass('active');
		
		changeBg(el,'item-pl-btn-stop.png');
		$(el).addClass('current').parent('li').addClass('active');
		
		$('#slFeatured').hide();
		$('#slVideoContainer').show();
		
		
		
		var videoClip = $(el).attr('rel') + '&curettype=1';
		var urlToPlay = '';
		$.get('/api/hole?s=' + new Date().getTime() + '&l='+escape(videoClip), function(data){
			urlToPlay = data.split(';')[0];
			$f('slVideoContainer',
				{
					src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', 
					wmode: 'opaque'	
				}, 
				{ 
				clip: { autostart: 'true', url: escape(urlToPlay), scaling: 'fit'},
				onLoad: function (){ this.setVolume(volumePosition); },
				onFinish: function () { stopVideoSpotlight(el);},
				plugins: {
					controls: null
					} 
				}
			);
		});	
		
		
		/*
		var videoClip = $(el).attr('rel');
		
		
		
		$f('slVideoContainer', 
			{ 
				src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', 
				wmode: 'opaque'
			}, 
			{ 
			    clip: {url: videoClip, scaling: 'fit'},
			    onLoad: function () { this.setVolume(volumePosition); },
			    canvas: {backgroundColor:'#000000', backgroundGradient: 'none'},
			    plugins: { controls: null}
		    }
		);
		*/	
		
		$(el).clone(true).appendTo('.videoControls');
		
		$('.videoControls .mv-play-btn').css('left','10px').css('top','5px');
		$('.videoControls').append('<a href="#" class="mv-fullscreen-btn" rel="div.overlay" id="fullScreenButton">Fullscreen</a>');
		$('.videoControls').show();
		
		$('#fullScreenButton').overlay({
			//effect: 'apple',
			onLoad: function() {
				$('.main-video > #slVideoContainer').remove();
				$('#overlayVideo').append('<div id="slVideoContainer"></div>');
				$('#overlayVideo > #slVideoContainer').css('width','810px').css('height','480px');
				$('#overlayVideo > #slVideoContainer').css('display','block');


						$f('slVideoContainer',
							{
								src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', 
								wmode: 'opaque'	
							}, 
							{ 
							clip: { autostart: 'true', url: escape(urlToPlay), scaling: 'fit'},
							onLoad: function (){ this.setVolume(volumePosition); },
							//onFinish: function () { $('#slVideoContainer').remove(); stopVideoSpotlight();},
							plugins: {
								//controls: null
								} 
							}
						);

				
				/*
				
				$f('slVideoContainer', 
					{ src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', wmode: 'opaque' }, 
					{ clip: {url: videoClip, autostart: 'true', scaling: 'fit'},
					  onLoad: function () { this.setVolume(volumePosition); },
					  canvas: {backgroundColor:'#000000', backgroundGradient: 'none'}//,
					 // plugins: { controls: null}
				    }
				);
				*/
				
				$('#slFeatured').show();
				$('.videoControls').empty().hide();
				$('.video-scroll-list ul > li').removeClass('active');
			},
			onClose: function() {
				$('#slVideoContainer').remove();
			   	stopVideoSpotlight();
			}
		});
		
	}

    function stopVideoSpotlight(el){
		stopSound();
		$('#slFeatured').show();
		$('.videoControls').empty().hide();
		$('#slVideoContainer').remove();
				
		$('.video-scroll-list ul > li').removeClass('active');
		//$('#topVideoPicture').show();
		
		
	}


	
		
	$('#playStreamVideoBtn').click(function (){
		stopSound();
		createEl('div','streamVideoContainer','.player-pic');
		$.get('/api/hole?s=' + new Date().getTime() + '&l=' + videoLink, function(data){
			var urlToPlay = data.split(';')[0].split('?');
			var streamer = urlToPlay[0] + '/';
			var streamURL = '_definst_%3F' + escape(urlToPlay[1]);
			$('#streamVideoContainer').show();
			$f('streamVideoContainer',
				{ src: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', wmode: 'opaque' }, 
				{ clip: { provider: 'rtmp', live: 'true', autostart: 'true', scaling: 'fit', url: streamURL },
					onLoad: function (){ this.setVolume(volumePosition); },
					canvas: { backgroundColor:'#000000', backgroundGradient: 'none'	},
					plugins: { rtmp: { url: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer.rtmp-3.1.3.swf', netConnectionUrl: streamer	}, controls: null }
				}
			);
			$('#topVideoPicture').hide();
			$('<div class="videoStreamControls"><a id="fullScreenStreamButton" rel="div.overlay" class="mv-fullscreen-btn" href="#" style="background:url(http://1062fm.co.il/static/templates/idc/i/bg/item-fullscreen-btn16.png) center center no-repeat;">Fullscreen</a><a id="stopStreamButton" class="mv-play-btn" href="#">Stop</a></div>').appendTo('#streamVideoContainer').show();
			$('#fullScreenStreamButton').css('left','110px');
			$('#stopStreamButton').css('left','85px').css('top','8px');
			changeBg('#stopStreamButton','item-pl-btn-stop16.png');
			
			$('#stopStreamButton').click(function (){
				$('#streamVideoContainer').remove();
				$('#videoStreamControls').remove();	
				$('#topVideoPicture').show();	
			});
			
			$('#fullScreenStreamButton').overlay({
			//effect: 'apple',
			onLoad: function() {
				$('#streamVideoContainer').remove();
				$('#videoStreamControls').remove();	
				$('#topVideoPicture').show();	
				
				createEl('div','streamVideoContainer','.overlay');
				$('.overlay > #streamVideoContainer').css('width','810px').css('height','480px');
				$('.overlay > #streamVideoContainer').css('display','block');
				
				$.get('/api/hole?s=' + new Date().getTime() + '&l=' + videoLink, function(data){
					var urlToPlay = data.split(';')[0].split('?');
					var streamer = urlToPlay[0] + '/';
					var streamURL = '_definst_%3F' + escape(urlToPlay[1]);
				
					$f('streamVideoContainer', 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer-3.1.5.swf', { 
						clip: {
							provider: 'rtmp', live: 'true', autostart: 'true', scaling: 'fit', url: streamURL
							},
						onLoad: function (){ this.setVolume(volumePosition);  },
						canvas: { backgroundColor:'#ffffff', backgroundGradient: 'none'},
						plugins: {
							rtmp: { url: 'http://1062fm.co.il/static/js/libs/flowplayer/flowplayer.rtmp-3.1.3.swf', netConnectionUrl: streamer	},
							controls: {
								all: true,
    fullscreen: true
							}
							}
						}
					);
				});
			
				//$('.main-video').append('<div id="slVideoContainer"></div>');
				
				
				//stopVideoSpotlight();
			},
			onClose: function() {
				$('.overlay > #streamVideoContainer').remove();
			   	
			   	stopVideoSpotlight();
			}
		});
			
			
			
		});
		
			
   	

		
   	return false;
   	});	
	

	//top banners
	i = 1;
	$('.promo-block:first').show();
	setInterval(
		function() {
			$('.promo-block').hide();
			if (i >= banners_count) { i = 0; }
			$('#block_' + i).show();
			i++;
		}
	, 10000);
	





}); 


function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}


