
// auto clear for text fields class .autoclear

$(document).ready(function(){
		
		/** global ajax events */
		
		$.ajaxSetup( { timeout: 5000 } );
		
		$("label.info").bind("ajaxSend", function(){
							$("label.error").hide();
							$(this).html('loading...');
				$(this).show();
							
			}).bind("ajaxComplete", function(){
							$(this).hide();
							
		});
			
		$("label.error").bind("ajaxError", function(){
				$(this).show();
							$(this).html('error on loading. please try again');
		});
		
		/**
		 * ajax pages
		 */
		
		/*
		$('div#page div#menu ul li a, div#menu_bottom ul li a, a.ajax').click(function() {
			$("#content").load($(this).attr('href')+'/1');
			return false;
		});
		*/
			
        
        /** radio */
        
        //$('#radio').html('<object type="application/x-shockwave-flash" width="17" height="17" data="/radio/musicplayer.swf?playlist_url=/radio/playlist.xspf&autoload=true&repeat_playlist=true&autoresume=true&autoplay=true"><param name="movie" value="/radio/musicplayer.swf?playlist_url=/radio/playlist.xspf&autoload=true&repeat_playlist=true&autoresume=true&autoplay=true" /><param name="bgcolor" value="#d2e8c8"/></object>');
        
        $('span#remote_control a.stop').click(function() {
              $('#radio').empty();
              $('span#remote_control a.onair').css('background','url("../img/radio/stoped.gif") no-repeat top left')
        });
        
        $('span#remote_control a.play').click(function() {
              $("label.info").hide();
              $('#radio').html('<object type="application/x-shockwave-flash" width="1" height="1" data="/radio/musicplayer.swf?playlist_url=/radio/playlist.xspf&autoload=true&repeat_playlist=true&autoresume=true&autoplay=true"><param name="movie" value="/radio/musicplayer.swf?playlist_url=/radio/playlist.xspf&autoload=true&repeat_playlist=true&autoresume=true&autoplay=true" /><param name="bgcolor" value="#d2e8c8"/></object>');
              $('span#remote_control a.onair').css('background','url("../img/radio/onair.gif") no-repeat top left')
        });
        
        
        /**
         * remove info messages
         */
        
        $('label.info, label.error').click(function() {
                $(this).hide();
                
        });
	
        
        /**
         * splash fadding
         */
        
        $('div#splash').ready(function() {
                $('div#splash').hide();
                $('div#splash').fadeIn('slow');
        });
        
	/**
	 * change home news every 8s
	 */
	
/*
        setInterval( function() {
                $.getJSON('/news/get',
                      function(json) {
                        $('div.content.news.home a img#home_news_img').attr('src', '/' + json[0].news_file);
                        $('div.content.news.home div.text h3#news_title').html(json[0].news_title);
                        $('div.content.news.home div.text div#news_body').html(json[0].news_body);
                        $('div.content.news.home a.news_id').attr('href', '/news/' + json[0].news_id);
                       } 
               );
                
        }, 8000 );

*/
		/**
		* rotate reviews in splash page
		*/

        function review_count(CURRENT, TOTAL) {
                if(CURRENT < (parseInt(TOTAL)-parseInt(1))) {
                       return parseInt(CURRENT)+1;
                } else {
                    return 0;
                }
                
        }
        
        $('#splash span.tags_reviews span').css('display','none');
        $('.tags_reviews span small a').attr('target','#blank');
        
        var REVIEWS_SPLASH_COUNT = $('#splash .tags_reviews span').size();
        var SPLASH_COUNT_CURRENT = 1;
        
        
        // home rotate reviews
		
        function rotate_home() {
        $('#splash .tags_reviews span:eq('+SPLASH_COUNT_CURRENT+')').unbind().fadeOut('slow', function() {
                        SPLASH_COUNT_CURRENT = review_count(SPLASH_COUNT_CURRENT, REVIEWS_SPLASH_COUNT);
                        $('#splash .tags_reviews span:eq('+SPLASH_COUNT_CURRENT+')').fadeIn('slow');
                });
        }
        rotate_home();
        
		
        setInterval( function() {
                rotate_home();
        }, 4000 );
		
});
