$(function (){

		if ( (sunsuntvTime.getTime() >= 1322665200000) && (sunsuntvTime.getTime() < 1324821600000) ) {
		// FROM: 2011-12-01 0:00
		// TO: 2011-12-25 23:00
		$('#video-sannosuke').css({
			'background-image' : 'url("' + sunsuntvDesignUri + '/img/home/beta/push_design_christmas.png")', 
			'left' : '21px', 'top' : '-50px', 'padding-top' : '100px'
			});
		} else if ((sunsuntvTime.getTime() >= 1325343600000) && (sunsuntvTime.getTime() < 1326636000000) ) {
		// FROM: 2012-01-01 0:00
		// TO: 2012-01-15 23:00
		$('#video-sannosuke').css({
			'background-image' : 'url("' + sunsuntvDesignUri + '/img/home/beta/push_design_akeome.png")', 
			'left' : '21px', 'top' : '-50px', 'padding-top' : '100px'
			});
		} else if ((sunsuntvTime.getTime() >= 1328022000000) && (sunsuntvTime.getTime() < 1329228000000) ) {
		// FROM: 2012-02-01 0:00
		// TO: 2012-02-14 23:00
		$('#video-sannosuke').css({
			'background-image' : 'url("' + sunsuntvDesignUri + '/img/home/beta/push_design_valentine.png")', 
			'left' : '21px', 'top' : '-50px', 'padding-top' : '100px'
			});
		} else {
			// default
			$('#video-sannosuke').css({
					'background-image' : 'url("' + sunsuntvDesignUri + '/img/home/beta/push_design.png")', 
					'left' : '21px', 'top' : '-50px', 'padding-top' : '100px'
					});
		}

		sunsuntvPrNewDate = (sunsuntvTime.getTime() / 1000) - ( 3 * 24 * 60 * 60 );
		sunsuntvAnnouncerNewDate = (sunsuntvTime.getTime() / 1000) - ( 3 * 24 * 60 * 60 );

		$('#pr li').each(function (){
				var maxStr = 40;
				var $span = $(this).find('span');
				if ( parseInt($(this).data('sunsuntvDate')) > sunsuntvPrNewDate ) {
				$('<img src="' + sunsuntvDesignUri + '/img/home/alpha/new.gif" alt="" height="12" />').appendTo($(this).children('a'));
				maxStr = 37;
				}
				if ($span.text().length > maxStr) {
				$span.text( $span.text().slice(0,maxStr) + ' ... ' );
				}
		});

		$('#announcer li').each(function (){
				var maxStr = 16;
				var $span = $(this).find('span');
				if ( (( new Date($(this).data('sunsuntvDate')) ).getTime()) / 1000 > sunsuntvAnnouncerNewDate ) {
				$('<img src="' + sunsuntvDesignUri + '/img/home/alpha/new.gif" alt="" height="12" />').appendTo($(this).children('a'));
				maxStr = 13;
				}
				if ($span.text().length > maxStr) {
				$span.text( $span.text().slice(0,maxStr) + ' ... ' );
				}
		});

		$('#news-list li').each(function(){
				var $a = $(this).children('a');
				if ( $a.text().length > 15 ) {
					$a.text( $a.text().slice(0,16) + ' ...' );
				}
		});

		$('#recome').bind('contextmenu', function (e){alert('著作権保護のため、右クリックを禁止しています。ご了承ください。');return false;});

		var kssLogoCarousel;
		kssLogoCarousel = $('#logo-list').bxSlider({
				'speed' : 1000, 'controls' : false, 'randomStart' : false, 'auto' : true, 'pause' : 5000, 'displaySlideQty' : 7, 
				'moveSlideQty' : 1
				});

		if ( kssVideos.length > 0 ) {
			$('#video-link').append('<img id="video-thumb" src="/_/banner/video_' + kssVideos[0].post + '.jpg" alt="" title="' + kssVideos[0].title + '"/>');
			$('<img src="http://www.sunsuntv.co.jp/_/banner/video_' + kssVideos[0].post + '_on.jpg" alt="" />');
			$('#video-link').hover(function (){
					$('#video-thumb').attr('src', '/_/banner/video_' + kssVideos[0].post + '_on.jpg');
					},
					function (){
					$('#video-thumb').attr('src', '/_/banner/video_' + kssVideos[0].post + '.jpg');
					});
		}

		$('#video a').fancybox({
				'padding' : 0, 'margin' : 0, 'width' : 640, 'height' : 390, 'autoScale' : false, 'autoDimensions' : false, 
				'scrolling' : 'no', 'overlayOpacity' : 0.9, 'overlayColor' : '#333', 'showCloseButton' : false, 
				'onStart' : function (){
				if ( $('#slider').data('nivoslider') ) {$('#slider').data('nivoslider').stop();}
				kssLogoCarousel.stopShow();
				sunsuntvHash = location.hash;
				location.hash='#lightbox-video';
				},
				'onClosed' : function (){
				if ( $('#slider').data('nivoslider') ) {$('#slider').data('nivoslider').start();}
				kssLogoCarousel.startShow();
				location.hash = sunsuntvHash;
				},
				'onComplete' : function () {}, 'onCleanup' : function () {}
				});

		$('#premiere-single a').fancybox({
				'padding' : 0, 'margin' : 0, 'width' : 800, 'height' : 800, 'autoScale' : false, 'autoDimensions' : false, 
				'scrolling' : 'yes', 'overlayOpacity' : 0.75, 'overlayColor' : '#333', 'showCloseButton' : true, 
				'onStart' : function (){
				if ( $('#slider').data('nivoslider') ) {$('#slider').data('nivoslider').stop();}
				kssLogoCarousel.stopShow();
				sunsuntvHash = location.hash;
				location.hash='#lightbox-premiere';
				},
				'onClosed' : function (){
				if ( $('#slider').data('nivoslider') ) {$('#slider').data('nivoslider').start();}
				kssLogoCarousel.startShow();
				location.hash = sunsuntvHash;
				},
				'onComplete' : function () {}, 'onCleanup' : function () {}
				});

$(window).bind('hashchange',function(){
if (location.hash !== '#lightbox-video' && location.hash !== '#lightbox-premiere' ) {$.fancybox.close();}
});


		$('<img id="program-catch" src="' + sunsuntvDesignUri + '/img/home/beta/onair.gif?' + sunsuntvTime.getTime() + ' " />').appendTo('#program h1');

		var sunsuntvCurrentHour = sunsuntvTime.getHours();

		if (sunsuntvCurrentHour < 4) {
			sunsuntvCurrentHour = sunsuntvCurrentHour + 24;
		}

		sunsuntvCurrentTime = (sunsuntvCurrentHour*100) + sunsuntvTime.getMinutes();

		var tt = document.getElementById('timetable');
		var myRows = tt.getElementsByTagName('tr');
		var myHeight = 0;
		var myPrvHeight = 0;
		var myElm = document.getElementById('program-list');
		myElm.scrollTop = 0;
		var i = 0;
		var sunsuntvCurrentProgram = myRows[0];
		for (i = 0; i < myRows.length; i++) {
			var myCell = myRows[i].getElementsByTagName('td')[0];
			var myID = myCell.childNodes[0].data;
			var myTime = myID.replace(':', '');
			myTime = myTime.replace('pg-', '');
			myTime = parseInt(myTime);
			if (myTime > sunsuntvCurrentTime) { break; }
			myPrvHeight = myHeight;
			myHeight += $(myRows[i]).height();
			sunsuntvCurrentProgram = myRows[i];
		}
		$(sunsuntvCurrentProgram).addClass('currentProgram');
		myElm.scrollTop = myPrvHeight;
});

$(window).load(function (){
	if ( !sunsuntvRecomeBannerFlag && sunsuntvRecomes.length > 1 ) {
		for ( i=1; i<sunsuntvRecomes.length; i++ ) {
			$('<a href="http://web.sunsuntv.co.jp/recome/#entry-' + sunsuntvRecomes[i].ID + '"><img src="http://a.sunsuntv.co.jp/recome/post_img/' + sunsuntvRecomes[i].ID + '_600.jpg" alt="' + sunsuntvRecomes[i].title + '" /></a>').appendTo('#slider');
		}

		$('#slider').nivoSlider({
			animSpeed : 500,
			pauseTime : 8000,
			controlNav : false,
			controlNavThumbs : false,
			controlNavThumbsFromRel : false, 
			prevText : '&laquo;',
			nextText : '&raquo;' 
			});
	}

		});


