/* search_predict_ajax.js */
var timeout = setTimeout("useLess()", 1);;
function useLess(){
}

function predictSearch(id) {	
	var search_value = id.value;
	if(search_value.length > 1){        
        $.ajax({
           type: "GET",
           url: '/ajax/search_predict.php',
           data: ({
                    keyword: search_value
                  }),
           success : showResults
        });	
	}
	//startTimeout(id);
}


function showResults(xhr) {    
	if(xhr != ""){
	    /*	
        var cat = document.getElementById('cat');
		if(cat){
			cat.className = 'hidden';
		}
		var filter = document.getElementById('filter');
		if(filter){
			filter.className = 'hidden';
		}
        */
		
		$('#search_predict').removeClass();
		$('#search_predict').html(xhr);
	} else {		
		$('#search_predict').addClass('hidden');
		$('#search_predict').html('');
	}    
}

function doSearchPredict () {
    predictSearch(document.getElementById('search_term'));
}

function startTimeout(search_field){
	if(search_field.value == "" || search_field.value == 'Search for videos...'){
		var timeout = setTimeout("clearPredict()", 5000);
	}
}

function clearPredict(){
	if(typeof timeout != 'undefined' && timeout){
		clearTimeout(timeout);
	}
	$('#search_predict').addClass('hidden');
	$('#cat').removeClass();
	$('#filter').removeClass();
}

/* the_warning.js */
function gayWarning(e) {
    //killVideoThumbs();    
    document.getElementById('GayWarn').style.display = 'block';
    document.getElementById('TrannyWarn').style.display = 'none';
    
    //check_and_check(['filter_type_straight', 'filter_type_tranny'], 'filter_type_gay', false);
    //document.getElementById('filter_type_gay').checked = 'checked';
    
    
    scroll(0,0)
    return false
}

function trannyWarning(e) {
    //killVideoThumbs();    
    document.getElementById('GayWarn').style.display = 'none';
    document.getElementById('TrannyWarn').style.display = 'block';
    
    //check_and_check(['filter_type_straight', 'filter_type_gay'], 'filter_type_tranny', false);
    //document.getElementById('filter_type_tranny').checked = 'checked';
    
    scroll(0,0)    
    return false
}


function scanLinks(elementID,word,event,callback) {
    if($('#' + elementID).length > 0) {    
        var links = document.getElementById(elementID).getElementsByTagName('a');
        if (links != null) {
            for (var i = 0, l = links.length; i < l; i++) {            
                if(links[i].href.indexOf(word) > -1) {
                    if (links[i].addEventListener) { //W3C                        
                        links[i].addEventListener(event, callback,false);
                    } else if (links[i].attachEvent) { //IE 
                        links[i].attachEvent( "on"+event,function() {return callback(this);});
                    }                
                }            
            }
        }
    }
}


function initWarning() {    
    if (arguments.callee.complete) return;    
    arguments.callee.complete = true;    
    if (_timer) clearInterval(_timer);
    
    if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)){    
        if(document.cookie.indexOf('gay') > -1) {
        	//leftColumn for left category menu
        	scanLinks('leftColumn','gay','click', gayWarning);
        	
        	//centerColumn for center pictures menu from channels.php page
        	if(location.pathname.indexOf('channels.php') == 1){
        		//we are for sure on channels.php page
        		scanLinks('centerColumn','gay','click', gayWarning);
        	}
        }
      
      	if(document.cookie.indexOf('tranny') > -1) {
    		scanLinks('leftColumn','shemale','click', function() {return trannyWarning(this);});
    		
    		//centerColumn for center pictures menu from channels.php page
    		if(location.pathname.indexOf('channels.php') == 1){
    			//we are for sure on channels.php page
    			scanLinks('centerColumn','shemale','click', function() {return trannyWarning(this);});
    		}
    	}
    	
    	//Not filter set up
    	if(document.cookie.indexOf('content_filter=') == -1) {    		
            scanLinks('leftColumn','gay','click', gayWarning);
    		scanLinks('leftColumn','shemale','click', function() {return trannyWarning(this);});
    		
    		//centerColumn for center pictures menu from channels.php page
    		if(location.pathname.indexOf('channels.php') == 1){
    			//we are for sure on channels.php page
    			scanLinks('centerColumn','gay','click', gayWarning);
    			scanLinks('centerColumn','shemale','click', function() {return trannyWarning(this);});
    		}		
    	}  
  } else {    
    if(document.cookie.indexOf('gay') > -1) {
		scanLinks('leftColumn','gay','click',   function(e) {e.preventDefault(true); return gayWarning(this);});
		
		//centerColumn for center pictures menu from channels.php page
		if(location.pathname.indexOf('channels.php') == 1){
			//we are for sure on channels.php page
			scanLinks('centerColumn','gay','click',   function(e) {e.preventDefault(true); return gayWarning(this);});
		}
	}
  
  	if(document.cookie.indexOf('tranny') > -1) {
		scanLinks('leftColumn','shemale','click',function(e) {e.preventDefault(true); return trannyWarning(this);});
		
		//centerColumn for center pictures menu from channels.php page
		if(location.pathname.indexOf('channels.php') == 1){
			//we are for sure on channels.php page
			scanLinks('centerColumn','shemale','click',function(e) {e.preventDefault(true); return trannyWarning(this);});
		}
	}
	
	//Not filter set up
	if(document.cookie.indexOf('content_filter=') == -1) {
		scanLinks('leftColumn','gay','click',   function(e) {e.preventDefault(true); return gayWarning(this);});
		scanLinks('leftColumn','shemale','click',function(e) {e.preventDefault(true); return trannyWarning(this);});
		
		//centerColumn for center pictures menu from channels.php page
		if(location.pathname.indexOf('channels.php') == 1){
			//we are for sure on channels.php page
			scanLinks('centerColumn','gay','click',   function(e) {e.preventDefault(true); return gayWarning(this);});
			scanLinks('centerColumn','shemale','click',function(e) {e.preventDefault(true); return trannyWarning(this);});
		}	
	}
  
  } 
};


//Opera / Moz
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", initWarning, false);
}

//IE
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      initWarning(); // call the onload handler
    }
  };
/*@end @*/

//Safari
if (/WebKit/i.test(navigator.userAgent)) {
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      initWarning(); 
    }
  }, 10);
}

//the rest
window.onload = initWarning;

/* thumbnail_change.js */
// Copyright 2003 All Rights Reserved - Tnaflix Team - www.tnaflix.com
// DO NOT REMOVE THIS HEADER

var thumbnail_preview_org_name;
var thumbnail_preview_basename;	
var thumbnail_preview_index = -1;
var thumbnail_preview_object = null;	
var thumbnail_preview_timer_start;
var thumbnail_preview_image = null;
var thumbnail_preview_timer = null;
var thumbnail_preview_run_delay = 450;
var thumbnail_preview_VID = null;	
var thumbnail_preview_premium = false;
function thumbnail_preview_start_obj(image){
	var screenshot = image.src;
	thumbnail_preview_premium = false;
	if(image.className.indexOf('premium_thumb') >= 0){
		thumbnail_preview_premium = true;
		thumbnail_preview_object = image;
		thumbnail_preview_org_name = screenshot;
		var i = screenshot.lastIndexOf('_');	
		var last_slash = (screenshot.lastIndexOf("/"));
		thumbnail_preview_basename = screenshot.substring(0, last_slash + 1);
		thumbnail_preview_VID = screenshot.substring(i +1);
		 thumbnail_preview_index = 1;
		 thumbnail_preview_timer = setTimeout(thumbnail_preview_run, 0);
	}else if (screenshot.indexOf('tnaflix') > 0 ) {	
		//get current frame
		var i = screenshot.lastIndexOf('_');		
		var e = screenshot.lastIndexOf('.');
		var last_slash = (screenshot.lastIndexOf("/"));
		thumbnail_preview_object = image;
		thumbnail_preview_org_name = screenshot;
		thumbnail_preview_index = 1;
		//thumbnail_preview_basename = screenshot.substring(0, 36);
		thumbnail_preview_basename = screenshot.substring(0, last_slash + 1);
		thumbnail_preview_VID = screenshot.substring(i +1, e);
		//showMyTrace("start_obj_done");	
		thumbnail_preview_timer = setTimeout(thumbnail_preview_run, 0);
    } else if (screenshot.indexOf('empflix') > 0) {
        var i = screenshot.lastIndexOf('-');        
	    thumbnail_preview_object = image;
	    thumbnail_preview_org_name = screenshot;
	    thumbnail_preview_index = 1;
	    thumbnail_preview_basename = screenshot.substring(0, i);
	    //showMyTrace("start_obj_done");    
	    thumbnail_preview_timer = setTimeout(thumbnail_preview_run, 0);    
    }
	
}

function thumbnail_preview_stop(){ 
	//Stop the animation
	//showMyTrace("stop");		
	if (thumbnail_preview_object == null) return;	
	clearTimeout(thumbnail_preview_timer);
	thumbnail_preview_index = 1;
	thumbnail_preview_object.src = thumbnail_preview_org_name;
	thumbnail_preview_object = null;
}

function thumbnail_preview_run(){
	//Run teh animation
	//showMyTrace("run");		
	if (thumbnail_preview_object == null) return;		
	//showMyTrace(thumbnail_preview_object);	
	thumbnail_preview_timer_start = new Date().getTime();	
	thumbnail_preview_image = new Image();
	//showMyTrace(thumbnail_preview_index);
	if(thumbnail_preview_premium) {
		thumbnail_preview_image.src = thumbnail_preview_basename + thumbnail_preview_index + "_" +thumbnail_preview_VID;   
	}else 	if (thumbnail_preview_basename.indexOf('tnaflix') > 0) {   
        thumbnail_preview_image.src = thumbnail_preview_basename + thumbnail_preview_index + "_" + thumbnail_preview_VID + '.jpg';    
    } else if (thumbnail_preview_basename.indexOf('empflix') > 0) {
        thumbnail_preview_image.src = thumbnail_preview_basename +"-"+ thumbnail_preview_index + '.jpg';    
    }
	
	//showMyTrace("the source : "+thumbnail_preview_image.src);
	thumbnail_preview_timer = setTimeout(thumbnail_preview_run_img, 50);		
	//showMyTrace("run_done");
}

function thumbnail_preview_run_img(){
	if (thumbnail_preview_object == null) return;		
	if (!thumbnail_preview_image.complete){
		thumbnail_preview_timer = setTimeout(thumbnail_preview_run_img, 80);
		return;
	}		
	if (thumbnail_preview_image.width == 0){
		thumbnail_preview_stop();
		return;
	}		
	var ix1 = thumbnail_preview_index;
	if(thumbnail_preview_premium) {
		thumbnail_preview_object.src = thumbnail_preview_basename + thumbnail_preview_index + "_" +thumbnail_preview_VID;   
	}else  if (thumbnail_preview_basename.indexOf('tnaflix') > 0) {   
        thumbnail_preview_object.src = thumbnail_preview_basename + thumbnail_preview_index + "_" + thumbnail_preview_VID + '.jpg';    
    } else if (thumbnail_preview_basename.indexOf('empflix') > 0) {
        thumbnail_preview_object.src = thumbnail_preview_basename +"-"+ thumbnail_preview_index + '.jpg';    
    }
	
	

	if (++thumbnail_preview_index > 30){
	 thumbnail_preview_index = 1;
	 }

	var timer_digit = new Date().getTime() - thumbnail_preview_timer_start;
	var timer_digit1 = timer_digit;
	if (timer_digit > thumbnail_preview_run_delay){
		timer_digit = 50;
	} else {
		timer_digit = thumbnail_preview_run_delay - timer_digit;
		if (timer_digit < 150) timer_digit = 150;
	}

	//showMyTrace(timer_digit1 + ', ' + timer_digit + ' - ' + thumbnail_preview_object.src);

	//showMyTrace("run_img_done");
	
	thumbnail_preview_timer = setTimeout(thumbnail_preview_run, timer_digit);
}

var thumbnail_preview_org_name2;
var thumbnail_preview_basename2;
var thumbnail_preview_index2 = -1;
var thumbnail_preview_src2 = null;
var thumbnail_preview_timer_start2;
var thumbnail_preview_image2 = null;
var thumbnail_preview_timer2 = null;
var thumbnail_preview_run_delay2 = 450;
var thumbnail_preview_VID2 = null;

function thumbnail_preview_start_obj2(imagesrc){
	var screenshot = imagesrc;
	//get current frame
	var i = screenshot.lastIndexOf('_');
	var e = screenshot.lastIndexOf('.');
	var last_slash = (screenshot.lastIndexOf("/"));
	thumbnail_preview_src2 = imagesrc;
	thumbnail_preview_org_name2 = screenshot;
	thumbnail_preview_index2 = 1;
	//thumbnail_preview_basename = screenshot.substring(0, 36);
	thumbnail_preview_basename2 = screenshot.substring(0, last_slash + 1);
	thumbnail_preview_VID2 = screenshot.substring(i +1, e);
	//showMyTrace("start_obj_done");
	thumbnail_preview_timer2 = setTimeout(thumbnail_preview_run2, 0);
}

function thumbnail_preview_stop2(){
    //Stop the animation
    //showMyTrace("stop");
    if (thumbnail_preview_src2 == null) return;
    clearTimeout(thumbnail_preview_timer2);
    thumbnail_preview_index2 = 1;
    thumbnail_preview_src2 = thumbnail_preview_org_name2;
    thumbnail_preview_src2 = null;
    document.getElementById('multiviewStartAuto').setAttribute('src', thumbnail_preview_org_name2);
}

function thumbnail_preview_run2(){
    //Run teh animation
    //showMyTrace("run");
    if (thumbnail_preview_src2 == null) return;
    //showMyTrace(thumbnail_preview_object);
    thumbnail_preview_timer_start2 = new Date().getTime();
    thumbnail_preview_image2 = new Image();
    //showMyTrace(thumbnail_preview_index);
    thumbnail_preview_image2.src = thumbnail_preview_basename2 + thumbnail_preview_index2 + "_" + thumbnail_preview_VID2 + '.jpg';
    document.getElementById('multiviewStartAuto').setAttribute('src', thumbnail_preview_basename2 + thumbnail_preview_index2 + "_" + thumbnail_preview_VID2 + '.jpg');
    //showMyTrace("the source : "+thumbnail_preview_image.src);
    thumbnail_preview_timer2 = setTimeout(thumbnail_preview_run_img2, 50);
    //showMyTrace("run_done");
}

function thumbnail_preview_run_img2(){
    if (thumbnail_preview_src2 == null) return;
    if (!thumbnail_preview_image2.complete){
        thumbnail_preview_timer2 = setTimeout(thumbnail_preview_run_img2, 80);
        return;
    }
    if (thumbnail_preview_image2.width == 0){
        thumbnail_preview_stop2();
        return;
    }
    var ix1 = thumbnail_preview_index2;
    thumbnail_preview_src2 = thumbnail_preview_basename2 + thumbnail_preview_index2 + "_" + thumbnail_preview_VID2 + '.jpg';
    document.getElementById('multiviewStartAuto').setAttribute('src', thumbnail_preview_basename2 + thumbnail_preview_index2 + "_" + thumbnail_preview_VID2 + '.jpg');
    if (++thumbnail_preview_index2 > 30){
     thumbnail_preview_index2 = 1;
     }
    var timer_digit = new Date().getTime() - thumbnail_preview_timer_start2;
    var timer_digit1 = timer_digit;
    if (timer_digit > thumbnail_preview_run_delay2){
        timer_digit = 50;
    } else {
        timer_digit = thumbnail_preview_run_delay2 - timer_digit;
        if (timer_digit < 150) timer_digit = 150;
    }
    //showMyTrace(timer_digit1 + ', ' + timer_digit + ' - ' + thumbnail_preview_object.src);
    //showMyTrace("run_img_done");
    thumbnail_preview_timer2 = setTimeout(thumbnail_preview_run2, timer_digit);
}



function showMyTrace(s){
	return false;
	var tdiv = document.getElementById("mytracer");
	tdiv.style.visibility = "visible";
	tdiv.innerHTML = s + "<br />" + tdiv.innerHTML;
}


/* video_prev.js */
/*
   COPYRIGHT TNAFLIX 2007
   ALL RIGHTS RESERVED
   www.tnaflix.com

   Tested in: Opera, Safari, IE6-8, Firefox, Chrome
*/
var isFF = (navigator.userAgent.indexOf('Firefox') > -1 ? true : false) ;
var isIE = (navigator.userAgent.indexOf('MSIE') > -1 ? true : false) ;
var curThumbURL = '';
var lastscroll = -1;
var lastMultiVID = 0;
var lastMultiVIDisPremium = false;
var multiplusdiv = '';
var multiparam1 = '';
var multiparam2 = '';
var multiparam3 = '';
var multiparam4 = readCookie('video_type_preview');
var last_thumb = "";
var _current_play = "";
var thumb1;
var movie1;
var file1;
var target1;
var timeouts;
window.addThisToMultiview = false;

if (multiparam4 != 'image') multiparam4 = 'video';

var MVNr = document.getElementById('MVNr');
if(MVNr){
	MVNr.innerHTML = countMultiVID();
}

document.body.setAttribute('onbeforeunload', 'firefix = false;');

function goToThumb() {
    if(curThumbURL != '') {
        document.location = curThumbURL;
    }
    return false;
}

function getFlashMovie(movieName) {
    var wind = window.document[movieName] ;
    var doc = document[movieName];
    var embeds = document.embeds[movieName];
    if(wind != false) return wind;
    if(doc != false) return doc;
    if(embeds != false) return embeds;
    return false;
}

function IsIE8Browser() {
    var rv = -1;
    var ua = navigator.userAgent;
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null) {
        rv = parseFloat(RegExp.$1);
    }
    return (rv == 4);
}

function findPos(obj, isMultiView){
    var posX = obj ? obj.offsetLeft : 0;
    var posY = obj ? obj.offsetTop : 0;
    if (obj)
    while(obj.offsetParent){
        if(obj==document.getElementsByTagName('body')[0]){
            break
        } else {
            posX=posX+obj.offsetParent.offsetLeft;
            posY=posY+obj.offsetParent.offsetTop;
            obj=obj.offsetParent;
        }
    }
    if(!isMultiView) {
    	//get window size
	    if(!window.innerWidth) {
	        if(!(document.documentElement.clientWidth == 0)) {
	            w = document.documentElement.clientWidth;
	        } else {
	            w = document.body.clientWidth;
	        }
	    } else {
	        w = window.innerWidth;
	    }
	    if(IsIE8Browser() && (w % 2)) {
	    	posX = posX - 1;
	    }
	}
    var posArray=[posX,posY]
    return posArray;
}

function fireFoxFix(){
	if(isFF) {
		var flash = document.getElementById('thumb');
		var pos = findPos(flash);
		if(pos[0] > 0 && pos[1] > 0){
		   flash.style.left = '-900px';
		   flash.style.top = '-900px';
	    }
	}
}

function firstLoadThumbMulti(){
    getFlashMovie('videoThumbMulti').startMovie(thumb1, movie1, file1, target1);    
}

function postMovie(item) {
	clearTimeout(timeouts);
}
function movieStartPromo(thumb, movie, file, target, vid,hd) {
	_current_play = vid;
	lastMultiVIDisPremium = hd;
	clearTimeout(timeouts);
	timeouts = setTimeout( "movieStartBase('"+thumb+"','"+ movie+"','"+ file+"','"+ target+"','"+ vid+"','"+ multiview_switch+"',1)", _delay_thumb );
}

function movieStart(thumb, movie, file, target, vid) {
	lastMultiVIDisPremium = false;
	_current_play = vid;
	clearTimeout(timeouts);
    // Check if video is inactive (concatenates -inactive to vid in draw_thumbnail movieStart call)	
	var list = vid.split('-');
	if (list[1] == 'inactive') {	
		vid = list[0];
		timeouts = setTimeout( "movieStartBase('"+thumb+"','"+ movie+"','"+ file+"','"+ target+"','"+ vid+"', 0)", _delay_thumb ); 
	} else {
		timeouts = setTimeout( "movieStartBase('"+thumb+"','"+ movie+"','"+ file+"','"+ target+"','"+ vid+"',"+ multiview_switch+")", _delay_thumb ); 
		
	}
}

function movieStartBase(thumb, movie, file, target, vid, activeMultiview, hdPromo) {  
	if (typeof getFlashMovie == 'undefined') { return false;}
	else if(typeof getFlashMovie('videoThumb') == 'undefined'){ return false;}
	if (_current_play != vid) { return false; }
    var image = findPos(document.getElementById(thumb));    
    var findvid = vid;
    if (lastMultiVIDisPremium) {
    	findvid = vid+'_'+lastMultiVIDisPremium;
    	$("#hdmovieRelIELink").css('display','block');
    	$("#hdmovieRelIELink").removeClass().addClass('dvdIconThumb').addClass( $('#hdIcon'+findvid).attr('class'));    	
    } else 	if ($("#hdIcon"+vid).length > 0){
    	$("#hdmovieRelIELink").css('display','block');
    	$("#hdmovieRelIELink").removeClass().addClass('dvdIconThumb').addClass( $('#hdIcon'+vid).attr('class'));    	
    }else {
    	$("#hdmovieRelIELink").css('display','none');    	
    }
    if (vid && activeMultiview == 1) {
        window.addThisToMultiview = vid;        
          
        if (findVideoInCookie(findvid)) {
            $('#addToMultiviewIELink').css('display', 'none');
            $('#multiaddedIELink').css('display', 'block');
        } else {
            $('#addToMultiviewIELink').css('display', 'block');
            $('#multiaddedIELink').css('display', 'none');
        }
    }
    
    if (activeMultiview == 0) {
        $('#addToMultiviewIELink').css('display', 'none');
        $('#multiaddedIELink').css('display', 'none');        
    }
    
    if(image[0] > 0 && image[1] > 0){
        $('#thumb').css('left', (image[0]+1)+'px');
        $('#thumb').css('top', (image[1]+1)+'px');
    }
    if(isFF == true) {
        $('#videoThumb').css('position', 'relative');
        $('#videoThumb').css('position', '');
    }
    curThumbURL = target;
    if(typeof getFlashMovie('videoThumb').startMovie == 'function') {        
    	//if (hdPromo && hdPromo == 1) {    		
    	//	getFlashMovie('videoThumb').startMovie(thumb, movie, file, target, 'http://pr-cdn.tnaflix.com/player_v0.3.18.swf?config='+ baseurl +'/thumb_hd_config.php?vid='+vid);
    	//} else {
    		getFlashMovie('videoThumb').startMovie(thumb, movie, file, target);
    	//}
    }
}


function movieStart2(thumb, movie, file, target) {    
    var image = findPos(document.getElementById(thumb), true);
    $('#thumbMulti').css('zIndex', 10);
    $('#thumbMulti').css('left', (image[0]+1)+'px');
    $('#thumbMulti').css('top', (image[1]+1)+'px');
    curThumbURL = target;
        
    if(typeof getFlashMovie('videoThumbMulti').startMovie == 'function') {        
        getFlashMovie('videoThumbMulti').startMovie(thumb, movie, file, target);
    } else {
        thumb1 = thumb;
        movie1 = movie;
        file1 = file;
        target1 = target;
    }
}

function smovieStart(thumb, movie, file, target) {    
    var image =  findPos(document.getElementById(thumb));
    
    if(image[0] > 0 && image[1] > 0){
        $('#thumb').css('left', (image[0]+1)+'px');
        $('#thumb').css('top', (image[1]+1)+'px');
    }
    if(isFF == true) {
        $('#videoThumb').css('position', 'relative');
        $('#videoThumb').css('position', '');
    }
    curThumbURL = target;
    getFlashMovie('videoThumb').startMovie(thumb, movie, file, target);
}

function hideJpeg(thumb, movie){
    var movieItem = document.getElementById(movie);
    var image = document.getElementById(thumb);
    //image.className = 'hidden';
    movieItem.className = '';
}


function showJpeg(thumb){
    if(thumb == "" && last_thumb != ""){
        thumb = last_thumb;
    } else {
        last_thumb = thumb;
    }
    var image = document.getElementById(thumb);
    if(image){
        image.className = '';
    }
}

function killVideoThumbs() {    
    $('#thumb').css('left', '-900px');
    $('#thumb').css('top', '-900px');
}

function killVideoThumbs2() {    
    $('#thumbMulti').css('left', '-900px');
    $('#thumbMulti').css('top', '-900px');    
}

function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function delValFromCookieArr(val, arr){
    var cc_value = '';
    var found = false;
    var cookieContent = readCookie(arr);
    if(cookieContent != null && cookieContent != ''){
        var arrVals = cookieContent.split(',');
        for(var i = 0; i < arrVals.length; i++){
            if(arrVals[i] != val){
                if(cc_value != ''){
                    cc_value += ',' + arrVals[i];
                }else{
                    cc_value = arrVals[i];
                }
            } else {
                found = true;
            }
        }
        eraseCookie(arr);
        setCookie(arr, cc_value, 30);
    }
    return found;
}

function removeOldestAddedVideo(){
    var selectedVids = readCookie('MultiSelectedVideos');
    if(selectedVids != null && selectedVids != ''){
        var selectedArr = selectedVids.split(',');
        // delete oldest selected video from cookie and uncheck corresponding checkbox
        vidDel = selectedArr[0];
        var cbDel = document.getElementById('multicb' + vidDel);
        cbDel.checked = false;
        delValFromCookieArr(vidDel, 'MultiSelectedVideos');
    }
}

function changeDivPlace(){
    var multidiv = $('#Multi_Plex');
    //get window size
    if(!window.innerWidth)
    {
        if(!(document.documentElement.clientWidth == 0))
        {
            h = document.documentElement.clientHeight;
            w = document.documentElement.clientWidth;
        }
        else
        {
            h = document.body.clientHeight;
            w = document.body.clientWidth;
        }
    }
    else
    {
        h = window.innerHeight;
        w = window.innerWidth;
    }
    var scrolled = getScrollTop();
    var currentLocation = window.location.href;
    var multiDivLeftOffset = {'view_video': 450}[currentLocation.substring(
        currentLocation.lastIndexOf('/') + 1,
        currentLocation.lastIndexOf('.')
    )];
    if (!multiDivLeftOffset) {
        multiDivLeftOffset = 295;
    }
    if(multidiv.css('display') != 'block') {
        if(isIE) {
        	multidiv.css('top', Math.round(scrolled + (h / 2) - 140)+'px');
        } else {
            multidiv.css('top', Math.round((h / 2) - 140)+'px');
        }
        multidiv.css('left', Math.round((w / 2) - multiDivLeftOffset)+'px');
        saveMultiviewEditorPosition(Math.round((w / 2) - multiDivLeftOffset), Math.round((h / 2) - 140));
        lastscroll = scrolled;
    }
}

function changeDivPlaceOnScroll(){    
    var multidiv = document.getElementById('Multi_Plex');
    var scrolled = getScrollTop();
    if(scrolled != lastscroll && multidiv.style.display == 'block') {
        multidivPos = findPos(multidiv);
        multidiv.style.top = (scrolled - lastscroll + multidivPos[1])+'px';
        if(multiparam4 == 'video') {
            var flash = document.getElementById('thumbMulti');
            var image = findPos(document.getElementById('multiviewStartAuto'));
            flash.style.zIndex = 10;
            flash.style.left = (image[0]+1)+'px';
            flash.style.top = (image[1]+1)+'px';
        }
        lastscroll = scrolled;
    }
}

if(isIE) {
	setInterval('changeDivPlaceOnScroll()', 1);
} 

function showMulti(videoid,sceneid){
if (sceneid == undefined){
	if (lastMultiVIDisPremium != false){
		sceneid = lastMultiVIDisPremium;
	}
}	

//lastMultiVIDisPremium = sceneid == false ? false : true;
try {
	var multidiv = $('#Multi_Plex');
    var multivideo = $('#multivideo');
    
    changeDivPlace();
    //set last multi vid
    if(videoid != 0){
    	lastMultiVID = videoid;
    	
    	//add show multiview

    	//$("div#remove" + videoid).html('<div class="multiadded" id="multiadded' + videoid + '" style="display: block; z-index: 1;"><div>Added to <span onclick="showMultiView(\'' + videoid + '\');">Multi-View</span></div></div>');
    	var target = "div#remove" + videoid;
    	var tmpid =  videoid;
    	if (sceneid != undefined) {
    		target += "_" + sceneid;
    		tmpid += "_" + sceneid;
    		$(target).html('<div class="multiadded" id="multiadded' + tmpid + '" style="display: block; z-index: 1;"><div>Added to <span onclick="showMultiView(\'' + videoid + '\',\'' + sceneid + '\');">Multi-View</span></div></div>');
    	} else {
    		$(target).html('<div class="multiadded" id="multiadded' + tmpid + '" style="display: block; z-index: 1;"><div>Added to <span onclick="showMultiView(\'' + videoid + '\');">Multi-View</span></div></div>');
    	}
    	//add to multi view
    	addMultiView(sceneid);
        var str= '';
        multivideo.html(str.replace(/<div class="videoExtra">(.*)<\/div>/mgi, ''));
    }else{
    	refreshMultiView();
    }
    //Show add button
    var name = "MultiVID";
    var tosearch = videoid;    
    if (lastMultiVIDisPremium){
   	 tosearch = videoid + '_' + lastMultiVIDisPremium;
   }    
    c_start=document.cookie.indexOf(name + "=");
    if (c_start != -1)
    {
        c_start = c_start + name.length + 1;
        c_end = document.cookie.indexOf(";", c_start);
        if(c_end == -1){
            c_end = document.cookie.length;
        }
        if((document.cookie.indexOf(',' + tosearch + ',', c_start) != -1 ||
           document.cookie.indexOf(tosearch + ',', c_start) != -1 ||
           document.cookie.indexOf(',' + tosearch, c_start) != -1 ||
           document.cookie.substring(c_start,c_end) == tosearch) && videoid != 0)
        {
            changeStyle({MPaddedbutton : 'block', MPaddbutton : 'none', 'videoid' : 'none'});
        }else if(videoid != 0){
            changeStyle({MPaddedbutton : 'none', MPaddbutton : 'block', 'videoid' : 'block'});
        }else{
            changeStyle({MPaddedbutton : 'none', MPaddbutton : 'none'});
        }
    }
    multidiv.css('display', 'block');
    } catch(e) {alert(e);}
}

function showMultiView(vid,scene){
    showMulti(vid,scene);
}

function showVideoThumb(videoid,isHD){
	isHD = isHD != undefined ? isHD : false;
	if (!isHD) lastMultiVIDisPremium =  false;
    if (videoid) {
        killVideoThumbs();
        killVideoThumbs2();
        thumbnail_preview_stop2();
        var multiview_list = $('#multivideo');
        lastMultiVID = videoid;
        multiview_list.html('<div style="text-align:center;width:100%;"><img src="/images/spinna.gif" alt="Loading your request" style="margin: 0 auto; border: 0;" /></div>');        
        if(isHD)
        {	
            $.ajax({
                type: "GET",
                url: '/ajax/get_video_thumb.php',
                data: ({
                        videoid: videoid,
                        sceneid: isHD,
                        m: Math.floor(Math.random()*100000),
                        premium:'true'
                      }),
                success: showVideoThumb_handler
            }); 
        }else{
            $.ajax({
                type: "GET",
                url: '/ajax/get_video_thumb.php',
                data: ({
                        videoid: videoid,
                        m: Math.floor(Math.random()*100000),
                        premium:'false'
                      }),
                success: showVideoThumb_handler
            }); 
        }
       
    }
}

function showVideoThumb_handler(xhr){    
    var responseText = xhr.split("|");
    
    $('#multivideo').html(responseText[1]);
    if(lastMultiVID !="" && countMultiVID() == 0) {
    	changeStyle({MPaddedbutton : 'none', MPaddbutton : 'block'});
    } else {
    	changeStyle({MPaddedbutton : 'block', MPaddbutton : 'none'});
    }
    multiparam1 = responseText[2];
    multiparam2 = responseText[3];
    multiparam3 = responseText[4];
    multiparam4 = responseText[5];
    if(multiparam4 == 'video') {        
        movieStart2('multiviewStartAuto', 'thumb', multiparam1, multiparam2);
    } else {
        thumbnail_preview_start_obj2(multiparam1);
    }    
}

function addMultiView(sceneid){
	sceneid = sceneid != undefined ? sceneid : false;
    if(lastMultiVID > 0){
    	
    	if(sceneid != false){
    		lastMultiVIDisPremium = sceneid;
        	var s = sceneid != false ? lastMultiVID + '_' + sceneid : lastMultiVID;
        	appendCookie('MultiVID', s, 30);    		
    	}else{
    		appendCookie('MultiVID', lastMultiVID, 30);
    	}

        refreshMultiView();
    }
}

function addVideoToMultiView(vid) {
    if (vid) {
        showMulti(vid);
    }
}

function refreshMultiView(){	
    $('#MPplaylist').html('<div style="text-align:center;width:100%;"><img src="/images/spinna.gif" alt="Loading your request" /></div>');
        
    $.ajax({
        type: "GET",
        url: '/ajax/get_multiview_videos.php',
        data: ({
                videoid: lastMultiVID,
                m: Math.floor(Math.random()*100000)                    
              }),
        success: refreshMultiView_handler
    });
}

function refreshMultiView_handler(xhr) {    
	// Unescape cookie set from php which contains encoded ","
	var unescapedCookie = unescape(readCookie('MultiSelectedVideos'));
	eraseCookie('MultiSelectedVideos');
	setCookie('MultiSelectedVideos', unescapedCookie, 30);
    
    $('#MPplaylist').html(xhr);
    //Update multi video number    
    $('#multiVIDNr').html(countMultiVID());    
    
    if( $('#MVNr').length > 0 ){
        $('#MVNr').html(countMultiVID());
    }
    
    if($('#multiVIDNr').html() == '0'){
        $('#MPremoveall').css('display', 'none');
    }else{
        $('#MPremoveall').css('display', 'block');
    }
   sendToMultiView(0);
   showVideoThumb(lastMultiVID, lastMultiVIDisPremium);
    
}

function appendCookie(name, value, days) {
	if (document.cookie.length > 0)
    {
    	c_start=document.cookie.indexOf(name + "=");
        if (c_start != -1)
        {
            c_start=c_start + name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;

            // Check to see if the value is already in the name cookie
            currentCookie = readCookie(name);
            if(currentCookie.indexOf(',' + value) == -1 && currentCookie.indexOf(value + ',') == -1){
                if(document.cookie.substring(c_start,c_end) != '' &&  document.cookie.substring(c_start,c_end) != value){
                    value = unescape(document.cookie.substring(c_start,c_end)) + ',' + value;
                }
            }else{
                value = unescape(document.cookie.substring(c_start,c_end));
            }

        }
    }

    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    } else {
    	var expires = "";
    }    
    document.cookie = name+"="+value+expires+"; domain=.tnaflix.com; path=/";

    //Update multi video number    
    $('#multiVIDNr').html(countMultiVID());    
    
    if($('#MVNr').length > 0){
        $('#MVNr').html(countMultiVID());
    }
    
    if($('#multiVIDNr').html() == '0'){
        $('#MPremoveall').css('display', 'none');
    }else{
        $('#MPremoveall').css('display', 'block');
    }
    tosearch = (lastMultiVIDisPremium) ? lastMultiVID+'_'+lastMultiVIDisPremium : lastMultiVID;
    if(findVideoInCookie(tosearch)){
        //Show added button
        changeStyle({MPaddedbutton : 'block', MPaddbutton : 'none', 'videoid' : 'none'});
    }
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +value+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; domain=.tnaflix.com; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    document.cookie = name + "="+"; domain=.tnaflix.com; path=/";
    
    //Update multi video number    
    $('#multiVIDNr').html(countMultiVID());    
    
    if($('#MVNr').length > 0){
        $('#MVNr').html(countMultiVID());
    }
    
	// if cookie holding all playlist vids was erased
	if (name == 'MultiVID')
        $('#MPremoveall').css('display', 'none');
}

function removeMultiView(videoid,isHD){
	 isHD = isHD != undefined ? isHD : false;
    //Do action only after confirmation
    if(confirm('Are you sure you want to REMOVE this video from your MultiView playlist?')){
		/*
        var cc_value = '';
        var cookieContent = readCookie('MultiVID');
        if(cookieContent != null && cookieContent != ''){
            var multiVideos = cookieContent.split(',');
            for(var i = 0; i < multiVideos.length; i++){
                if(multiVideos[i] != videoid){
                    if(cc_value != ''){
                        cc_value += ',' + multiVideos[i];
                    }else{
                        cc_value = multiVideos[i];
                    }
                }
            }
            eraseCookie('MultiVID');
            appendCookie('MultiVID', cc_value, '1');
        }
		*/

        // Delete videoid from multiview videos array

        delValFromCookieArr(videoid, 'MultiVID');
        delValFromCookieArr(videoid, 'MultiSelectedVideos');
        if(isHD){
        		tmpvidel = videoid.split('_')[1];
        		delValFromCookieArr(tmpvidel, 'MultiVIDPremium');
        		document.getElementById('MPaddbutton').href = "javascript:addMultiView('" + tmpvidel + "');";
        		 $('#multiadded'+videoid).css('display', 'none');
        } else {
        	document.getElementById('MPaddbutton').href = "javascript:addMultiView();";
        }
        plusSign_Restore(document.getElementById('multiplus'+videoid));
        videoid = isHD ? videoid.split('_')[0] : videoid;
        //hide div
        $('#MPaddedvid_' + videoid).addClass('hidden');
        $('#MPaddedvid_' + videoid).html('');
        
        if(videoid == lastMultiVID ||( lastMultiVIDisPremium && (videoid==lastMultiVID+'_'+lastMultiVIDisPremium))){
            //Update buttons
            changeStyle({MPaddedbutton : 'none', MPaddbutton : 'block', 'videoid' : 'block'});
        }
        //Update
        sendToMultiView(videoid);
        //Remove added div
        if($('#multiadded'+videoid).length > 0){
            $('#multiadded'+videoid).css('display', 'none');
        }
    }
}

function plusSign_Restore(el)
{
    if (el) {
        el.style.display = 'block';
        el.style.position = 'absolute';
        el.style.left = '150px';
    }
}

function removeAllMultiView(){
    if(confirm('Are you sure you want to REMOVE ALL videos from your MultiView playlist?')){
        $('#MultiView_VideoList').html('');

        eraseCookie('MultiVID');
        eraseCookie('MultiVIDPremium');
        eraseCookie('favs_added');
        var multilastvid = ($('#multivideo').children('.video').length > 0) ?  $('#multivideo').children('.video').attr('id').split('video')[1] : "";
        if(multilastvid.indexOf('_') > 0){

    		document.getElementById('MPaddbutton').href = "javascript:addMultiView('" + multilastvid.split('_')[1] + "');";
        } else {
        	document.getElementById('MPaddbutton').href = "javascript:addMultiView();";
        }
        //Update buttons
        if(lastMultiVID > 0){
            changeStyle({MPaddedbutton : 'none', MPaddbutton : 'block', MPplayoff : 'none', MPplayon : 'block', MPmessages : 'block'});
        }else if(lastMultiVID == 0){
            changeStyle({MPaddedbutton : 'none', MPaddbutton : 'none', MPplayoff : 'none', MPplayon : 'block', MPmessages : 'block'});
        }
        
        //Add back plus sign
        var elements = getElementsByClassName(document, "div", "multi");
        for(var i=0; i<elements.length; i++){
            plusSign_Restore(elements[i]);
        }

        //Remove added
        var elements = getElementsByClassName(document, "div", "multiadded");
        for(var i=0; i<elements.length; i++){
            elements[i].style.display = 'none';
            //elements[i].innerHTML = '';
        }   
        $('#StartMultiView').attr('href', '/multiview_player.php');     
    }
}

function countMultiVID(){
    var c_val = readCookie('MultiVID');
    var newval = '';
    var length = 0;
    if(c_val != null && c_val != '' && c_val != ' '){
        var multiVIDNr = c_val.split(',');
        for(var i=0; i<multiVIDNr.length; i++){
            if(multiVIDNr[i] != ''){
                if(newval != ''){
                    newval += ',' + multiVIDNr[i];
                }else{
                    newval += multiVIDNr[i];
                }
                length++;
            }
        }
        if(newval != '' && length != multiVIDNr){
            document.cookie = "MultiVID" + "="+"; domain=.tnaflix.com; path=/";
            var date = new Date();
            date.setTime(date.getTime()+(30*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
            document.cookie = "MultiVID"+"="+newval+expires+"; domain=.tnaflix.com; path=/";
        }
        
    }
    var f_val = readCookie('MultiVIDPremium');
    if(f_val != null && f_val != '' && f_val != ' '){
    	var multiPrem = f_val.split(',');
    	for(var i=0; i<multiPrem.length; i++){
    		length++;
    	}	
    }       
    return length;
}

function findVideoInCookie(videoid){
    var cc_value = '';
    var cookieContent = readCookie('MultiVID');
    if(cookieContent != null && cookieContent != ''){
        var multiVideos = cookieContent.split(',');
        for(var i = 0; i < multiVideos.length; i++){
            if(multiVideos[i] == videoid){
                return true;
            }
        }
    }
    return false;
}

function findValueInCookieArray(val, arr){
    var cc_value = '';
    var cookieContent = readCookie(arr);
    if(cookieContent != null && cookieContent != ''){
        var arrVals = cookieContent.split(',');
        for(var i = 0; i < arrVals; i++){
            if(arrVals[i] == val){
                return true;
            }
        }
    }
    return false;
}

function delValFromCookieArr(val, arr){
    var cc_value = '';
    var found = false;
    var cookieContent = readCookie(arr);
    if(cookieContent != null && cookieContent != ''){
        var arrVals = cookieContent.split(',');
        for(var i = 0; i < arrVals.length; i++){
            if(arrVals[i] != val){
                if(cc_value != ''){
                    cc_value += ',' + arrVals[i];
                }else{
                    cc_value = arrVals[i];
                }
            } else {
                found = true;
            }
        }
        eraseCookie(arr);
        appendCookie(arr, cc_value, 30);
    }

    return found;
}

function sendToMultiView(uncheck, vid){
    //MultiVIDCheck
    var totalChecked = 0;
    var totalElements = 0;
    var multiQuery = '';

    $('#MPplayoff').css('display', 'block');
    $('#MPplayon').css('display', 'none');
    $('#MPmessages').css('display', 'block');
    
    //loop through each CheckBox
    for (var i = 0; i < document.forms['MultiPlexForm'].elements.length; i++)
    {
        var e=document.forms['MultiPlexForm'].elements[i];
        if (e.type == 'checkbox')
        {
            if(uncheck != 0 && e.value == uncheck){
                e.checked = false;
            }
            e.disabled = false;
            if(e.checked == true){
                totalChecked++;
            }
            totalElements++;
        }
    }

    if (vid > 0) {
        var cbSel = document.getElementById('multicb'+vid);
        if (cbSel.checked == false) {
            // if unchecked, remove from selected videos
            delValFromCookieArr(vid, 'MultiSelectedVideos');
        } else {
            var currSel = readCookie('MultiSelectedVideos');
	        eraseCookie('MultiSelectedVideos');
	        // Add newly selected video
	        if (currSel != '') {
	           setCookie('MultiSelectedVideos', currSel + ',' + vid, 30);
	        } else {
	           setCookie('MultiSelectedVideos', vid, 30);
	        }
	        if (totalChecked >= 5) {
	           removeOldestAddedVideo();
	           totalChecked--;
	        }
        }
    }
        
    $('#MPplayoff').css('display', 'none');
    $('#MPplayon').css('display', 'block');
    $('#MPmessages').css('display', 'none');
    //loop through each CheckBox
    for (var i = 0; i < document.forms['MultiPlexForm'].elements.length; i++)
    {
        var e=document.forms['MultiPlexForm'].elements[i];
        if (e.type == 'checkbox')
        {
            if(e.checked != true){
                //e.disabled = true;
            }
            else if(e.checked == true){
                if(multiQuery == ''){
                    multiQuery = e.value;
                }else{
                    multiQuery = multiQuery + ',' + e.value;
                }
            }
        }
    }
    var url = baseurl + '/multiview_player.php?vids=' + escape(multiQuery);                                                    
    $('#StartMultiView').attr('href', url);
    
}

function changeStyle(){
    var i = '';
    var idtochange = '';
    for(i in arguments[0]){
    	idtochange = lastMultiVIDisPremium ? lastMultiVID+'_'+lastMultiVIDisPremium : lastMultiVID;
        if(i == 'videoid'){
            if($('#multiplus'+idtochange).length > 0){
                $('#multiplus'+idtochange).css('display', arguments[0][i]);
            }
            if(arguments[0][i] == 'block'){
                if($('#multiadded'+idtochange).length > 0){
                    $('#multiadded'+idtochange).css('display', 'none');
                }
            }else{
                if($('#multiadded'+idtochange).length > 0){
                    $('#multiadded'+idtochange).css('display', 'block');
                    $('#multiadded'+idtochange).css('zIndex', 1);
                }
            }
        }else{
            if($('#' + i).length > 0){
                $('#' + i).css('display', arguments[0][i]);
            }
        }
    }
}

//Start draggable functions
function MPdrag(e){
    t = document.getElementById('Multi_Plex');
    if (e.preventDefault) e.preventDefault(); //line for IE compatibility
    e.cancelBubble = true;
    window.document.onmousemoveOld = window.document.onmousemove;
    window.document.onmouseupOld = window.document.onmouseup;
    window.document.onmousemove=MPdodrag;
    window.document.onmouseup=MPstopdrag;
    window.document.draged = t;
    t.dragX = e.clientX;
    t.dragY = e.clientY;
    t.style.cursor = 'move';
    return false;
}

function MPdodrag(e){
	//get window size
    if(!window.innerWidth) {
        if(!(document.documentElement.clientWidth == 0)) {
            h = document.documentElement.clientHeight;
            w = document.documentElement.clientWidth;
        } else {
            h = document.body.clientHeight;
            w = document.body.clientWidth;
        }
    } else {
        h = window.innerHeight;
        w = window.innerWidth;
    }
    if (!e) e = event; //line for IE compatibility
    t = window.document.draged;
    t.style.left = (t.offsetLeft + e.clientX - t.dragX)+"px";
    t.style.top = (t.offsetTop + e.clientY - t.dragY)+"px";
    var multiviewEditorLeftPoistion = t.offsetLeft + e.clientX - t.dragX;
    var multiviewEditorTopPoistion = t.offsetTop + e.clientY - t.dragY;
    if(multiviewEditorLeftPoistion < -130) {
    	t.style.left = "-130px";
    } else if(multiviewEditorLeftPoistion > (w - 60)) {
    	t.style.left = (w - 60)+"px";
    }
    var topBecauseOfIE = -20;
    var bottomBecauseOfIE = h - 40;
    if(isIE) {
    	topBecauseOfIE = getScrollTop() - 20;
    	bottomBecauseOfIE = h - 40 + getScrollTop();
    }
    if(multiviewEditorTopPoistion < topBecauseOfIE) {
    	t.style.top = topBecauseOfIE+"px";
    } else if(multiviewEditorTopPoistion > bottomBecauseOfIE) {
    	t.style.top = bottomBecauseOfIE+"px";
    }
    if(multiparam4 == 'video') {        
        var image = findPos(document.getElementById('multiviewStartAuto'), true);
        if (image[0] != 0 && image[1] != 0) {
	        $('#thumbMulti').css('zIndex', 10);
	        $('#thumbMulti').css('left', (image[0]+1)+'px');
	        $('#thumbMulti').css('top', (image[1]+1)+'px');
	    }
    }
    t.dragX = e.clientX;
    t.dragY = e.clientY;
    return false;
}

function MPstopdrag(){
	window.document.onmousemove=null;
    window.document.onmouseup=null;
    t = window.document.draged;
    t.style.cursor = 'auto';
    var saveLeftPosition = t.offsetLeft;
    var saveTopPosition = t.offsetTop;
    if(isIE) {
    	saveTopPosition = t.offsetTop - getScrollTop();
    }
    saveMultiviewEditorPosition(saveLeftPosition, saveTopPosition);
}


function addFavsToMultiview(uid) {
    $.ajax({
        type: "GET",
        url: '/ajax/get_favourites_vids.php',
        data: ({
                uid: uid,
                m: Math.floor(Math.random()*100000)
              }),
        success: addFavsToMultiview_handler
    });    
}

function addFavsToMultiview_handler(xhr) {    
    appendCookie('favs_added', '1', 30);
    favs = xhr.split("|");
    for (i = 0; i < favs.length; i++) {
        if (i != favs.length - 1) {
            appendCookie('MultiVID', favs[i], 30);
			lastMultiVID = favs[i];
			changeStyle({MPaddedbutton : 'block', MPaddbutton : 'none', 'videoid' : 'none'});
        } else {
            showMulti(favs[i]);
        }
    }
    //refreshMultiView();
    
}

function showMultiviewEditor(disallowChangeDivPlace)
{
	var multidiv = $('#Multi_Plex');
	if(multidiv.css('display') != 'block') {
		if(!disallowChangeDivPlace) {
			changeDivPlace();
		}
		var listOfVidsCookie = readCookie('MultiVID');
		if(listOfVidsCookie) {
			var listOfVids = listOfVidsCookie.split(",");
			lastMultiVID = listOfVids[listOfVids.length - 1];
		}
		if (lastMultiVID != "" && lastMultiVID.indexOf('_')>0){
			lastMultiVID = lastMultiVID.split("_");
			lastMultiVIDisPremium = lastMultiVID[1];
			lastMultiVID = lastMultiVID[0];
		}
		/*if(lastMultiVID > 0 && countMultiVID() == 0) {
			showVideoThumb(lastMultiVID);
			changeStyle({MPaddedbutton : 'none', MPaddbutton : 'block', MPplayoff : 'block', MPplayon : 'none', MPmessages : 'block'});
		} else {*/
			refreshMultiView();
		/*}*/
		multidiv.css('display', 'block');
	}
}

function saveMultiviewEditorPosition(saveLeftPosition, saveTopPosition)
{
	setCookie('multiviewEditorPosition', saveLeftPosition+','+saveTopPosition);
}

function deleteMultiviewEditorPosition()
{
	setCookie('multiviewEditorPosition', '');
}

function openMultiviewEditor()
{
	var position = readCookie('multiviewEditorPosition');
	if(position) {
		var positionArray = position.split(',');
		var multidiv = $('#Multi_Plex');
		if(multidiv.css('display') != 'block') {
			multidiv.css('left', positionArray[0]+'px');
			multidiv.css('top', positionArray[1]+'px');
			showMultiviewEditor(true);
		}
	}
}

var listOfVidsCookieIE = readCookie('MultiVID');
if(listOfVidsCookieIE) {
	var listOfVidsIE = listOfVidsCookieIE.split(",");
	for(var i = 0; i < listOfVidsIE.length; i++) {
		if($('#multiplus'+listOfVidsIE[i]).length > 0) {
			$('#multiplus'+listOfVidsIE[i]).css('display', 'none');
		}
		if($('#multiadded'+listOfVidsIE[i]).length > 0) {
			$('#multiadded'+listOfVidsIE[i]).css('display', 'block');
		}
	}
}
function stopVideo()
{
	var vid = getFlashMovie('mpl');
	if(vid) {
		if (typeof vid.stopVideo == "function") {
			vid.stopVideo();
		}
	}
	return true;
}
function gotoSec(time) {
	document.getElementById('mpl').gotoSeconds(time);
	document.getElementById('mpl').scrollIntoView(true);
}

//End draggable function
// IE...
if (window.attachEvent)
	window.attachEvent("onresize", function(){killVideoThumbs2();thumbnail_preview_stop2();});
// FF etc.
else
	if(multiparam4 == 'video') {
		window.addEventListener("resize", killVideoThumbs2, true);
	} else {
		window.addEventListener("resize", thumbnail_preview_stop2, true);
	}
function showHint(item) {
	  var image = findPos(item);
	  $('#addMultiHint2').css('display','block');
	  $("#addMultiHint2").css('left',image[0]+'px');
	  $("#addMultiHint2").css('top',(image[1]-30)+'px');
}
function hideHint(item) {
	$("#addMultiHint2").hide();
}

/* captcha.js */
function make_uuid() {
    var uuid = "";
    for (var i = 0; i < 32; i++) {
        uuid += Math.floor(Math.random() * 16).toString(16)
    }
    return uuid;
}
function updateCaptcha(){
    var params = updateCaptcha.arguments;
    var paramsLength = updateCaptcha.arguments.length;
    var num = '';
    var extra = '';
    var width = '';
    var height = '';

    if(paramsLength >0){
        var num = (params[0] != '') ? params[0] : '';
        var extra = (params[1] != '') ? params[1] : '';
        var width = (params[2] != '') ? params[2] : '';
        var height = (params[4] != '') ? params[3] : '';
    }

    if ($('#captchaCode'+num).length) {
        $('#captchaCode'+num).attr('src', '');

        if(width == ''){
            $('#captchaCode'+num).css('width', '200px');
        }else{
            $('#captchaCode'+num).css('width', width+'px');
        }

        if(height == ''){
            $('#captchaCode'+num).css('height', '80px');
        }else{
            $('#captchaCode'+num).css('height', height+'px');
        }
    }

    if(num == ''){
        $('#captchaCode').attr('src', '/captcha.php?'+Math.random()+extra+'&width='+width+'&height='+height);
    }else{
        $('#captchaCode'+num).attr('src', '/captcha.php?'+Math.random()+'&num='+num+extra+'&width='+width+'&height='+height);
    }
}

/*
 *dialog title
 *msg to display
 *Function name to call
 *list of parameters in order the funciton call accept them
 **/
var $dialog;
function captchaDialog(){

    var params = captchaDialog.arguments;
    var paramsLength = captchaDialog.arguments.length;

    var functionCall;
    var functionCallParams = '';
    var uuid ;

    if (params['0'] == ''){
        captchaDialogTitle = 'Tnaflix Dialog Box';
    } else {
        captchaDialogTitle = params['0'];
    }

    if (params['1'] == ''){
        captchaDialogMsg = '&nbsp;';
    } else {
        captchaDialogMsg = params['1'];
    }

    if (captchaDialogMsg != '&nbsp;') {
        captchaDialogMsg = captchaDialogMsg + '<br><br>';
    }


    if(paramsLength > 0){
         $dialog = $('<div></div>')
                .dialog({
                autoOpen: false,
                title: captchaDialogTitle,
                width: 400,
                draggable: false,
                zIndex: 99999,
                modal: true,
                open: function(event, ui) { uuid = make_uuid(); },
                buttons: {
                        "Ok": function() {
                            captchaValCode = $('#captchaUserInputCode_'+uuid).val();
                            if(captchaValCode != '' ) {

                                for(i=4;i<paramsLength;i++){
                                   functionCallParams = functionCallParams + '"' +params[i]+'",';
                                }

                                functionCall = params[3]+'('+functionCallParams+'"'+captchaValCode+'",'+'"'+uuid+'");';
                                //alert(functionCall);
                                eval(functionCall);
                                $(this).dialog("close");
                            } else {
                                alert('Type the code in the image and click ok!');
                            }
                        },
                        "Cancel": function() {
                                $.ajax({
                                    type: "GET",
                                    url: '/ajax/captchaRemoved.php',
                                    data: ({
                                    uuid: uuid,
                                    action: 'delete'
                                }),
                                success : silentResponse
                                });
                                $(this).dialog("close");
                        }
                }
        });

        $dialog.dialog('open');
        $dialog.dialog("option","position",'top');

        if(params[3] != 'sndComment'){
            $dialog.html('<div style="margin-left: 5%; margin-right: 5%;"><div style="text-align:left">'+captchaDialogMsg+'<div style="font-size: .9em; font-style: italic;" id="captchaDialogBody">'+params[2]+'</div><br><br>Plese enter the code:</div><div style="float:left; margin-right: 10px;"><img id="captchaCode" src="/captcha.php?uuid='+uuid+'" class="captcha" width="115" height="45" /></div><div style="float:left; text-align:left;"><br><input type="text" name="captchaUserInputCode" id="captchaUserInputCode_'+uuid+'" autocomplete="off" /></div></div>');
        } else {
            $dialog.html('<div style="margin-left: 5%; margin-right: 5%;"><div style="text-align:left">'+captchaDialogMsg+'<div style="font-size: .9em; font-style: italic;" id="captchaDialogBody"></div><br><br>Plese enter the code:</div><div style="float:left; margin-right: 10px;"><img id="captchaCode" src="/captcha.php?uuid='+uuid+'" class="captcha" width="115" height="45" /></div><div style="float:left; text-align:left;"><br><input type="text" name="captchaUserInputCode" id="captchaUserInputCode_'+uuid+'" autocomplete="off" /></div></div>');
        }
    } else {
        alert('Invalid Options for Captcha');
    }
}


function silentResponse(xhr) {
    if(xhr != ""){}
}

