var currentVideoSub = 'videoInfo';
var ltcStatus = 0;
var vscStatus = 0;
var currentMediaBoxPanel = 'salesContainer_1_1a';




function frontInit(){
		
}

function init(){
	
	pageDisplay(54);	
}

function showTranslator(){
	
	document.getElementById("translateSwitch").style.display = 'none';
	$('#MicrosoftTranslatorWidget').fadeIn('fast');	
}

function searchOn(divId){
	

	if(divId == 'vsc'){
		if(vscStatus == 1){
			vscStatus = 0;	
			searchOff(divId);
		}else{
			vscStatus = 1;	
		}
	}
	divOn(divId);
	divOff();
}

function divOn(divId){
	checkOn(divId);
	$('#'+divId).style.display = 'block';
	
}
function checkOn(divId){
	

	if(divId == 'vsc'){
		vscStatus = 1;
		ltcStatus = 0;	
	}	
}
function divOff(){
	
	

	if(vscStatus == 0){
		document.getElementById("vsc").style.display = 'none';
	}
	
}

function forceDivClose(divId){
	$('#'+divId).fadeOut('fast');
}

function searchOff(divId){
	
	if(divId == 'vsc'){
		vscStatus = 0;	
	}
	timeoutID = window.setTimeout(divOff, 800);
	
}
function showCommentForm(){
	$('#commentForm').slideToggle();
}

function imposeMaxLength(Object, MaxLen)
{
	if(Object.value.length >= MaxLen){
		Object.value = Object.value.substr(0, MaxLen);
	}
    return(true);
}




function checkCommentForm(){
	var status = 1;	
	if($('#userComment').val().length == 0){
		status = 0;	
	}
	if($('#captcha_response').val().length != 4){
		status = 0;	
	}
	
	if(status == 1){
		return(true);	
	}else{
		alert("Please fill in the required fields");
		return(false);	
	}
	
}

function searchByCat(id, title, url){
	if(url != ""){
		$.ajax({
			   type: "GET",
			   url:"/ajax/increaseHitCount",
			   data:"catId="+id,
			  
			   error:function (xhr, ajaxOptions, thrownError){
					
					alert(thrownError);
				},
	
			   success: function(videos){
				 
					window.open(url,'mywindow','width=990,height=800,toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					
		 }});
	}else{
		$.ajax({
			   type: "GET",
			   url:"/ajax/getCategorisedVideo",
			   data:"catId="+id+"&catTitle="+title+"&catUrl="+url,
			  
			   error:function (xhr, ajaxOptions, thrownError){
					
					alert(thrownError);
				},
	
			   success: function(videos){
					$("#selectedChannel").html("<a href=\"#\">"+title+"</a>");
					$("#slidesOuter").html(videos);
					forceDivClose('vsc');
					
		 }});
	}
}


function backtoVideoList()
{
		
	document.location.href='/';	
}
/*
function searchByCat(id){
	
	$.ajax({
		   type: "GET",
		   url:"/ajax/getCategorisedVideo",
		   data:"catId="+id,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				
				alert(thrownError);
			},

	   	   success: function(videos){
			  
			  	searchOff('vsc'); 
				searchOff('ltc');
				document.getElementById("vsc").style.display = 'none';
				document.getElementById("ltc").style.display = 'none';
				$("#videoItemsNew").fadeOut('fast');
				$("#videoItemsPop").fadeOut('fast');
				$("#historyItems").fadeOut('fast');
				$("#videoItems").fadeIn('fast').html(videos);
				
				$("#RSMVideoList").fadeIn('fast');
				
					//console.log(videos);
				
				
	 }});
	
}
*/
function getRssFeedDataItem(id){
	$("#rssCat_"+id).fadeIn('fast');
	$.ajax({
		   type: "GET",
		   url:"/ajax/getRssFeedDetail",
		   data:"rssid="+id,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				console.log('Error:'+ thrownError);
				//alert(thrownError);
			},

	   	   success: function(result){
			  
			  
				$("#rssCat_"+id).html(result);
				
			
				
					//console.log(videos);
				
				
	 }});
	
}
function getRssFeedData(id){
	$("#rssCat_"+id).fadeIn('fast');
	$.ajax({
		   type: "GET",
		   url:"/ajax/getRssFeedFront",
		   data:"rssid="+id,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				console.log('Error:'+ thrownError);
				//alert(thrownError);
			},

	   	   success: function(result){
			  
			  
				$("#rssCat_"+id).html(result);
				
			
				
					//console.log(videos);
				
				
	 }});
	
}

function showPopup(action, userid) {
	$('#popup').animate({
    	opacity: 0.7
	});
	document.getElementById('popup').style.display = 'block';
	$('#window').fadeIn('fast');
	return false;
}
function closePopup() {
	$('#popup').fadeOut('fast');
	$('#window').fadeOut('fast');
}


function searchVideos(searchString)
{
	//console.log($("#userVideoSearch").val());
	
	//if(searchString != ''){
		$.ajax({
		   type: "POST",
		   url:"/ajax/getSearchVideo",
		   data:"searchTerms="+searchString,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				
				alert("No videos found with '"+searchString+"'");
			},

	   	   success: function(videos){
			  
			    	
				$("#slidesOuter").html(videos);
				//$("#videoItems").fadeIn('fast').html(videos);
				
				//$("#RSMVideoList").fadeIn('fast');
					//console.log(videos);
				
				
	 	}});
	//}
	return (false);
	
}

function checkLogin(form){
	
	document.getElementById("memberLoading").style.display = 'block';
	$.ajax({
	   type: "POST",
	   url: "/ajax/memberLogin",
	   data: "username="+form.username.value+"&password="+form.password.value,
	   cache: false,
	   async:false,
	   dataType:'json',
	   error: function(e, textStatus, errorThrown){
        alert("error:" + e+':'+textStatus+':'+errorThrown);
       }, 
	   success: function(res, textStatus, XMLHttpRequest){
		   	
			// console.log(res.data[0].type+':'+res.responseText+':'+textStatus+':'+XMLHttpRequest);
			 if(res.data[0].type == '1'){
				 $('#loggedin').fadeIn('fast');
				 $('#loggedout').fadeOut('fast');
				 $("#memberLoading").fadeOut('fast');
				 closePopup();
				 $.scrollTo( $('#videoInfoLinks'),800 );
			 }else{
				 $("#memberLoading").fadeOut('fast');
				 alert('Incorrect login details');	 
			 }
	   }
	});
	
	/*
	 $('#loggedin').fadeIn('fast');
	 $('#loggedout').fadeOut('fast');
	 closePopup();
	*/
	return (false);		
}

function videoTabView(divId){
	
	$('#'+divId+'_menu').addClass('active');
	$('#'+currentVideoSub+'_menu').removeClass('active');	
	
	if(divId == 'videoSlides'){
		
		
	}	
	$('#'+currentVideoSub).hide();
	currentVideoSub = divId;
	$('#'+divId).fadeIn('slow');
	
}
// JavaScript Document
/*
function init(){
	//new Resizable('columnOne', {constraint:'horizontal', onResize:updateColOne});
	//new Resizable('header', {constraint:'vertical'});
	
	//preloadImages();
	//enableDraggableItems();
	//preloadMenuList();
	//enableSortableList();
}
*/



function ajaxFormProcess(processPage)
{
	new Ajax.Request(processPage, {
			method: "post",
			parameters:$('menuItem').serialize(true), 
			onComplete:function(transport){
				new Effect.Fade('item_'+transport.responseText);
				messageDisplay(1);
				new Effect.Fade('pageSettings');
			}, 
			evalScripts:true
	});
	
}

function ajaxFormProcessAdd(processPage)
{
	new Ajax.Request(processPage, {
			method: "post",
			parameters:$('menuItem').serialize(true), 
			onComplete:function(transport){
			
				//new Effect.Fade('item_'+transport.responseText);
				new Effect.Fade('pageSettings');
				pageDisplay(transport.responseText);
				
			},
			evalScripts:true
	});
	
}

function messageDisplay(messageId)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/formMessage.php?t='+t+'&id='+messageId);
	// ]]>
}
function enableSortableList()
{
	
	Sortable.create('items_list0',{tree:true,dropOnEmpty: false, containment: 'items_list0', constraint: false,scrollSensitivity:0,scrollSpeed:0,ghosting:true,hoverclass:'menuHover',
		onChange:function(a,b,c) { },
		onUpdate: function() {
			new Ajax.Request("ajax/saveSort.php", {
			method: "post",
			parameters: { data: Sortable.serialize('items_list0') }
		});
	}});
}

function preloadImages()
{
	image1 = new Image();
	image1.src = "images/liArrow2.gif";
	image2 = new Image();
	image2.src = "images/message2.gif";
	image3 = new Image();
	image3.src = "images/deletePage2.gif";
	image4 = new Image();
	image4.src = "images/pageSettings2.gif";
	image5 = new Image();
	image5.src = "images/addSubMenu2.gif";
	image6 = new Image();
	image6.src = "images/deletePage.gif";
	image7 = new Image();
	image7.src = "images/pageSettings.gif";
	
}

function preloadMenuList(id)
{
	
	var listObj = $('items_list'+id);
	var childCount = listObj.childNodes.length;
	
	var listOptions= '';
	for(var i=0;i<childCount;i++){
		//startPos = listObj.childNodes[i].id.indexOf('_')+1;
		
		//menuId = listObj.childNodes[i].id.substr(startPos);
		//alert(listObj.childNodes[i].innerHTML);
		//listOptions += menuId +' ';
		//openMenuList(menuId,'tertiaryMenuItems_'+menuId);
	}
	
	
	//alert(listOptions);
	//enableSortableList();
}

function redirect(url)
{
	document.location.href=url;
}

function deleteSubMenu(pageid)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/menuDelete.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true, onComplete:showPageForms});
	// ]]>
	
}


function addSubMenu(pageid)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/pageForms.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true, onComplete:showPageForms});
	// ]]>	
	
}

function showPageForms()
{
	new Effect.Appear('pageForms');
}

function pageDisplay(pageid)
{
	
	$.ajax({
		   type: "POST",
		   url: "index.php/ajax/retrieve",
		   data: "id="+pageid,
		   success: function(msg){
		     
		     $('#columnTwo').html(msg);
		   }
	});
	// <![CDATA[	
	/*
	var ajax;
	var d = new Date();
	var t = d.getTime();
	new Effect.Appear('columnTwo');
	ajax =  new Ajax.Updater(
		 'columnTwo',  
		 'ajax/pageContent.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true});
	// ]]>	
	*/
}

var currentSubMenu = '';
var subMenus = new Array();
var subMenuIterator = 0;
var workingMenu ='';

function toggleListMenu(id, divName)
{
	var divId = divName+id;
	//togglePageDetails(id, divId);
	// <![CDATA[
	
	if(workingMenu != divId){
		workingMenu = divId;
		currentSubMenu = subMenuIterator;
		subMenus[subMenuIterator++] = divId; 
		var subMenuIndex = subMenus.indexOf(divId);
		if(subMenuIndex == -1){
			if($(divId).style.display == 'none'){
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}else{
			currentSubMenu = subMenuIndex;
			if($(divId).style.display == 'none'){
				
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}
		
	
	}else{
		//alert('just bloody wait');	
	}
	// ]]>	
}


function togglePageDetails(pageId, divId)
{
	
	// <![CDATA[
	
		pageDisplay(pageId);
		var ajax;
		var d = new Date();
		var t = d.getTime();
		var subMenuIndex = subMenus.indexOf(divId);
		
		if($(divId).style.display == 'none'){
			/*
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/menu.php?parentId='+parentId+'&t='+t,{method:'get',asynchronous:true, onComplete:showSubMenu});
			*/
			new Effect.BlindDown(divId);
		}else{
			
			new Effect.BlindUp(divId);
			
		}

	
	
	// ]]>	
}

function openMenuList(parentId, divId){
	// <![CDATA[
	
	if(workingMenu != divId){
		workingMenu = divId;
		var ajax;
		var d = new Date();
		var t = d.getTime();
		var subMenuIndex = subMenus.indexOf(divId);
		if(subMenuIndex == -1){
			if($(divId).style.display == 'none'){
				
				ajax =  new Ajax.Updater(
					 divId,        		// DIV id must be declared before the method was called
					 'ajax/menu.php?parentId='+parentId+'&t='+t,{method:'get',asynchronous:true, onComplete:showSubMenu});
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}else{
			currentSubMenu = subMenuIndex;
			if($(divId).style.display == 'none'){
				
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}
		currentSubMenu = subMenuIterator;
		subMenus[subMenuIterator++] = divId; 
	
	}else{
		//alert('just bloody wait');	
	}
	// ]]>	
}

function allowMenuProcess()
{
	//alert(workingMenu);
	workingMenu = '';	
}


function showSubMenu()
{
	setTimeout(allowMenuProcess,1001);	
	new Effect.BlindDown(subMenus[currentSubMenu]);
	
}


function toggleRightMenu()
{
	if($('columnTwo').style.width =='5px'){
		$('rightMenuControl').style.backgroundImage = 'url(images/rightMenuControl.gif)';
		$('rightSide').style.display = 'block';
		$('columnTwo').style.width = "346px";
		$('columnOne').style.width = "551px";
		$('map').style.width = "570px";
	}else{
		$('rightMenuControl').style.backgroundImage = 'url(images/rightMenuControl_.gif)';
		$('rightSide').style.display = 'none';
		$('columnTwo').style.width = "5px";
		$('map').style.width = "878px";
		$('columnOne').style.width = "878px";
	}
	
}

function successHideRightSide()
{
	alert($('rightSide').style.display);
}




function updateColOne(resizable, event){
	var delta = resizable.currentDelta();
	$('columnTwo').style.width = (970 - delta[0]-55)+"px";
	$('columnOne').innerHTML = delta[0];
}

function redirect(url){
	document.location.href=url;	
}

function primaryMenu(id)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new Ajax.Updater(
		 "pageContent",        		// DIV id must be declared before the method was called
		 'ajax/pageContent.php?id='+id+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage});

	// ]]>
}

var sMenu = 1;
var tMenu =1;
var tParent = null;
var currentPage = null;
var currentSMenu = null;
var currentSBG = null;
var currentSC = null;

function setMenuOn(){
	sMenu = 1;	
}

function setTMenuOn(){
	tMenu = 1;	
}
 
function rollover(divId){
	//$('header').innerHTML = divId +':'+tParent;
	if(divId != tParent && divId != currentSMenu){
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#FFF';
	}
	
}
function rollout(divId){
	if(currentSMenu != divId){
		$(divId).style.backgroundColor = '#f8f8f8';
		$(divId).style.color = '#333';
	}
	parentId = null;
}

function rollover2(divId, parentId){
	tParent = parentId;
	if(divId != currentSMenu){
		
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#FFF';
	}
}
function rollout2(divId){
	
	tParent = null;
	if(currentSMenu != divId){
		$(divId).style.backgroundColor = '#FFFFFF';
		$(divId).style.color = '#5b5b5b';
	}
}

function closeSubMenu(pId){
	
	if($('tert_'+pId).style.display == ''){
		
		new Effect.BlindUp('tert_'+pId);
	}
	
}

function secondaryMenu(pId, sId, obj){	
	// <![CDATA[
	if($('tert_'+pId)){	
		if($('tert_'+pId).style.display == 'none'){	
			
			new Effect.Appear('tert_'+pId);
			new Effect.Fade('arrow_'+pId);
		}
	}
	setTimeout ( "setMenuOn()",500);
	
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#f8f8f8";
		currentSC = "#333";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");	
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function tertiaryMenu(pId, sId, obj){	
	// <![CDATA[
	if($('tert_'+pId)){			
		new Effect.Appear('tert_'+pId);
	}
	setTimeout ( "setMenuOn()",1000);
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#FFFFFF";
		currentSC = "#5b5b5b";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function showError(req){
	$('pageContent').innerHTML = req.responseText+"<br />Please try again";
}

function showPage(){

	if($('pageContent')){
		
	//	new Effect.Appear('pageContent');	
	}
	
}

function showJournal(id){
	$('journal_'+id).morph("height:100%");
	
}
function divOn(div)
{	
	document.getElementById(div).style.display = 'block';	
}
