

EVERYZING.getSeekParam = function () {
    var query = window.location.hash;
    if (!query  || query.length == 0) {
        query = window.location.search;
    }
    if (!query || query.length == 0) {
        return "";
    }
    var parts = query.substr(1).split("&");
    for (var i = 0; i < parts.length; i++) {
        if (parts[i].indexOf("seek=") == 0) {
            return unescape(parts[i].substr(5).replace(/\+/g, " "));
        }
    }
    return "";
};




/* ---[ BETTERTV HANDLE PLAYER ]--- */

function onStreamStart(evt) {
    var seek = EVERYZING.getSeekParam();

    if (seek.length > 0) {
        video.seek(seek);
    }
}

function onAdComplete(evt) {
    var seek = EVERYZING.getSeekParam();

    if (seek.length > 0) {
        video.seek(seek);
    }
}
		
/* ---[ Truncate Scenes text, burn from both ends ]--- */
EVERYZING.scene_truncate = function(node,maxLen,flag, prefix, postfix){
	maxLen = parseInt(maxLen, 10);
	if (isNaN(maxLen)){
		maxLen = 160;
	}
	//Keep the snippet from being truncated to nothing
	if (maxLen < 10) {
		maxLen = 10;	
	}
	
    if (prefix == null || prefix.length == 0){
        prefix = "";
    }
    if (postfix == null || postfix.length == 0){
        postfix = "&#8230;";
    }
	
	node.contents().find("a",".ez-videoScene").each(function(){
		var content = this.innerHTML;
		content = content.replace(/<B/g, '<b');
		content = content.replace(/<\/B>/g, '</b>');
		
		var text = $(this).text();
		var newContent;
		if (text.length > maxLen) {
			var i = content.indexOf('<b');
			var j = content.indexOf('</b>');
			
			var pre = content.slice(0, i);
			pre = pre.slice(-1 * maxLen / 2);
			pre = pre.replace(/^[a-z0-9.]* /i, '');
			
			var post = content.slice(i, content.length);
			
			var targetPostLen = maxLen - pre.length;
			var targetPostText = text.slice(i, targetPostLen + i);
			targetPostText = targetPostText.replace(/&amp;/g, '&');
			
			var elemLen = 0;
			var buf = post;
			buf = buf.replace(/&amp;/g, '&');
			
			while (buf.indexOf(targetPostText) == -1) {
				var i = buf.indexOf('<');
				var j = buf.indexOf('>');
				elemLen += j - i + 1;
				
				buf = buf.slice(0, i) + buf.slice(j + 1, buf.length);
			}
			
			post = post.slice(0, targetPostLen + elemLen);
			post = post.replace(/[a-z0-9<>]+$/i, '');
			
			newContent = pre + post;
			newContent = $.trim(newContent);
			
			this.innerHTML = newContent;
			}
			var contentValue;
		if(!flag)
		{
			contentValue = newContent.replace(/<b>/g,'');
			contentValue = contentValue.replace(/<\/b>/g,'');
		}
		else
		{
			contentValue = this.innerHTML;
		}
		this.innerHTML = prefix + contentValue + postfix;
	});
};