
var GNMLS = {
	feed: 'http://www2.newson6.com/livestreaming/?s=KOTV&jsoncallback=?',
	init: function() {
		$('#gnmls').parent().css('margin-bottom', '0');
		$.getJSON(GNMLS.feed, function(data) {
			if (data.banners.length > 0) $('#gnmls').parent().css('margin-bottom', '15px');
			$.each(data.banners, function(i, item) {
				if (item.picture != "" && item.size == 'Full') {
					$('#gnmls').append('<div class="' + item.size + '"><img src="' + item.picture + '"><span class="line1"><a href="' + GNMLS.getLink(item) + '">' + item.line1 + '</a></span><span class="line2">' + item.line2 + '</span></div>');
				}
				else {
					$('#gnmls').append('<div class="' + item.size + '"><span class="line1"><a href="' + GNMLS.getLink(item) + '">' + item.line1 + '</a></span><span class="line2">' + item.line2 + '</span></div>');
				}
			});
			$('#gnmls div').each(function() {
				if($(this).hasClass('Half') && $(this).next().hasClass('Half')) {
					$(this).removeClass('Half');
					$(this).addClass('Half1');
					$(this).next().removeClass('Half');
					$(this).next().addClass('Half2');
				}
			});
		});
	},
	getLink: function(item) {
		var vLink;
		switch(item.encodertype) {
			case 'house':
				if (item.connstring == '')
					vLink = 'javascript:playLiveVideo(\'\', \'' + item.line1.replace(/"/g, '\\\'').replace(/'/g, '\\\'').replace(/\\\\/g, '\\') + '\', \'' + item.classification + '\', \'www.newson6.com\', \'flv\', \'\', \'1\', \'' + item.port + '\', \'' + item.profile + '\');';
				else
					vLink = 'javascript:playLiveVideo(\'' + item.connstring + '\', \'' + item.line1.replace(/"/g, '\\\'').replace(/'/g, '\\\'').replace(/\\\\/g, '\\') + '\', \'' + item.classification + '\', \'www.newson6.com\', \'flv\');';
				break;
				
			case 'cbs':
				vLink = 'javascript:GNMLS.playCBS();';
				break;
				
			case 'okblitz':
				vLink = item.connstring + item.articleid;
				break;
				
			case 'embed':
				vLink = item.connstring + item.embedcatid;
				break;
		}
		return vLink;
	},
	playCBS: function() {
		cbsfeed = window.open('http://kotv.images.worldnow.com/images/incoming/livestreaming/09/CBSNews/cbspageKOTV.htm', 'cbsfeed', 'width=708, height=747, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
	}
};

$(document).ready(function() {
	GNMLS.init();	
});

