tvgReferrer='ITV-BB-NAN';
tvgBranding='ITV';
tvgBroadcaster='BDSITVNowNextWidget';
tvgRegion='London';
tvgFirstChannelNumber=0;
tvgLastChannelNumber=899;
tvgNumberChannels=6;
tvgClockStyle='ampm';
tvgEPGNumberChannels=6;
tvgNumberHours=0;
tvgListingsAreaWidth=270;
tvgChannelColumnWidth=0;
tvgShowChannelLogo='Yes';
tvgShowLinks='Yes';
tvgIgnoreFavouriteChannels='Yes';
tvgListingsViewStyle='EPG';
tvgListingShowDaysDropDown='No';
tvgShowDetailsUrl='http://www.itv.com/tvguide/';
tvgShowDetailsDiv='tvgShowDetails';
tvgShowDetailsTarget='_blank';
tvgListingShow24hDropDown='No';
tvgListingsDiv='tvgListingComp';
tvgShowListingsPrefs='No';
tvgListingShowWholeDay='No';
tvgCookiePrecedence='None';

if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	tvgChannelLogoURL='/_devpacks/itvhome/tvguide/img/logos/ie6/'; 
}
else{
	tvgChannelLogoURL='/_devpacks/itvhome/tvguide/img/logos/'; 	
}

function tvgAjaxPreback(id)
{
 switch (id)
    {
  
    case 'tvgListingComp':

    break;
	
	default:
	
    break;
    }
	
}
function tvgAjaxCallback(id) {
	switch (id) {
			
	case "tvgListingComp":
		
		$('.tvg_listings_channel').each(function(){
			$(this).find('.tvg_listings_channel_progbox:first').addClass('first_show');
		});
		$('.tvg_listings_channel:last').css('border', 'none');
		
		$('span.tvg_listings_prog_title').each(function(index) {
			var shows = $(this).text();
			if((shows.length)>= 13){
				var new_title = $(this).text().substring(0, 13) + '...';
				$(this).text(new_title);    
			}
		});
		
		$('div.tvg_listings_channel').each(function(index) {
			if($('.tvg_listings_channel_name', this).length != 0){
				var channel_name = $('.tvg_listings_channel_name', this).text().toLowerCase();
			}
			else{
				var channel_name = $('.tvg_listings_channel_name_long', this).text().toLowerCase();	
			}
			$('div.tvg_listings_channel_logo_image', this).wrap('<a href="http://www.itv.com/' + channel_name + '/"></a>');
		});
			
		if ($.cookie('tvgBroadcasterStore') != null){
			restoreBroadcaster = tvgGetCookie('tvgBroadcasterStore');
			tvgClearCookie("tvgBroadcasterStore");			
			tvgSetCookie('tvgBroadcaster', restoreBroadcaster);	
			}
					
	break;

		
	case "tvgShowDetails":
	$('#tvgShowDetailsWrapper').css('display', 'block');
	var channel = $('#tvg_details_logo').text();
	live = $('a#watch_live');
	channelUrl(channel);
	var time = $('.tvg_details_timing_time').text();
	$('.tvg_details_title').after('<div id="time">' + time + '</div>');
	$('a.tvg_details_site_link_www').text('Show site');
	$('.tvg_details_site_link_catchup').text('Catch up');
	
	var desc = $('.tvg_details_description').text();
	if((desc.length)>= 200){
		var truncate = desc.substring(0, 200) + '...';
		$('.tvg_details_description').text(truncate);    
	}

	break;

	}
}

function channelUrl(channel){
	switch (channel){
	
	case "ITV1":
	channel_url(1);
	break;
	
	case "ITV2":
	live.attr('href', 'http://www.itv.com/channels/itv2/watchlive/');
	break;
	
	case "ITV3":
	channel_url(3);
	break;
	
	case "ITV4":
	channel_url(4);
	break;
	
	case "CITV":
	live.css('display', 'none');
	break;
			
	}
}

function channel_url(number){
	live.attr('href', 'http://www.itv.com/itv' + number + '/');
}

function tvgClose(div) {
	var el = document.getElementById(div);
	if (el.style.display != "none") {
		el.style.display = "none";
		if (div == "tvgShowDetailsWrapper") {
			tvgClearParameter("tvgShowID");
			tvgClearParameter("tvgEpisodeID");
			live.removeAttr('href');
			live.css('display', 'block');	
			$('#time').remove();
		}
	}
}

function widgetBroadcaster(){
	if ($.cookie('tvgBroadcaster') != null){
		storeBroadcaster = tvgGetCookie('tvgBroadcaster');
		tvgClearCookie("tvgBroadcaster");			
		tvgSetCookie('tvgBroadcasterStore', storeBroadcaster);
	}	
}
