/***********************************************************Scriptname: 	schedule.1.0.jsDependencies: 	jquery.1.4.3, phpjs.min.jsVersion: 		1.0 liveDescription:	UI for the schedule moduleCopyright: 		Webavance B.V. 2011 for Dusk!Legal: 			Any use of this script without Webavance B.V.				express written consent is prohibited************************************************************/(function($) {		$.fn.schedule = function(c) {		var elm = $(this);		if (!c) c = {};				c = $.extend({			json_schedule: '#',			menu: '*'		}, c);				$('.schedule_day_more').live('click', function(e){			var descr = $(this).siblings('.schedule_day_description');			if (descr.css('display')=='none') {				elm.find('.schedule_day_description').css({ display: 'none' });				descr.css({ display: 'inline'});			} else {				descr.css({ display: 'none'});			}		});						var menu = $(c.menu);		menu.find('li').bind('click', function(e) {			menu.find('li').removeClass('active');			$(this).addClass('active');						var channels = new Array();			$(this).find('input').each(function(i, inp){				if (parseInt($(inp).attr('name'))>0) {					channels.push({						id: $(inp).val(),						name: $(inp).attr('name')					});				}			});						var logo = $(this).find('input[name=logo]').val();			_schedule_show(channels, logo);		});				menu.find('li:first').click(); // activate the first link				function _schedule_show(channels, logo) {			elm.children().remove();						$('<img class="schedule_logo" src="' + logo + '"/>').appendTo(elm);						if (channels[0]===undefined) return false; // no channels found so return						var chnnls = $('<ul class="clean schedule_channels"/>').appendTo(elm);						$('<li rel="0">Kanaal:</li>').appendTo(chnnls);						$(channels).each( function(x, chnl) {				$('<li rel="' + chnl.id + '">' + chnl.name + '</li>')					.appendTo(chnnls)					.bind('click', function(e) {						_schedule_channel($(this).attr('rel'), $(this).text());					});			});						$('<div class="schedule_current_channel"/>').appendTo(elm);						_schedule_channel(channels[0].id, channels[0].name);		}				function _schedule_channel(id, name) {			elm.find('.schedule_day_wrapper').remove();			elm.find('hr').remove();						$('.schedule_current_channel').text('Kanaal ' + name);						$('.schedule_channels').find('li').removeClass('active');			$('.schedule_channels').find('[rel='+id+']').addClass('active');			if (id=='DUSK_PASSIE') {				_schedule_call(id, date('Y-m-d', time()) + ' 21:00:00', date('Y-m-d', time()+86400) + ' 00:24:00');			}			else {				_schedule_call(id, date('Y-m-d H:i:s'), date('Y-m-d', time()+86400) + ' 00:00:00');			}									if (id=='DUSK_247') {				_schedule_call(id, date('Y-m-d', time()+86400) + ' 00:00:00', date('Y-m-d', time()+86400) + ' 12:00:00');			} 			else if (id=='DUSK_PASSIE') {				_schedule_call(id, date('Y-m-d', time()+86400) + ' 21:00:00', date('Y-m-d', time()+172800) + ' 00:24:00');			} else {				_schedule_call(id, date('Y-m-d', time()+86400) + ' 00:00:00', date('Y-m-d', time()+86400) + ' 23:59:00');			}		}				function _schedule_call(channel, from, till) {			if (elm.find('.schedule_day_wrapper').length % 2 == 0) $('<hr/>').appendTo(elm);						var daywrapper = $('<div class="schedule_day_wrapper loading">').appendTo(elm);						$.ajax({				url: c.json_schedule,				cache: false,				dataType: 'json',				type: 'GET',				placein: daywrapper,				data: {					channel: channel,					from: strtotime(from),					till: strtotime(till)				},				success: function(data) {					var pi = $(this.placein);					pi.removeClass('loading');										$('<div class="schedule_day_head"><h4>' + data.day + '</h4></div>').appendTo(pi);					$(data.items).each( function(j, item) {						var html =	'<div class="schedule_day_item">' + 									'<div class="schedule_day_time">' + date('H:i', item.begin) + ' - ' + date('H:i', item.eind) + '</div>' + 									'<a class="schedule_day_more">meer info&raquo;</a>' + 									'<div class="schedule_day_title">' + item.titel + '</div>' + 									'<div class="schedule_day_description">' + item.description + '</div>' + 									'</div>';												$(html).appendTo(pi);					});				},				error: function(data) {					console.log('Could not load');				}			});		}	};	})($);
