function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function switch_d(div_id) {
		if (document.getElementById(div_id).style.display=="block")
		{
			document.getElementById(div_id).style.display="none";
		}
		else 
		{
			document.getElementById(div_id).style.display="block";
		}
}

function flip(div_id) {
	if (document.getElementById(div_id)) 
	{
		if (document.getElementById(div_id).style.display=="inline")
		{
				document.getElementById(div_id).style.display="none";
		}
		else 
		{
			document.getElementById(div_id).style.display="inline";
		}
	}
}

function close_d(div_id) {
document.getElementById(div_id).style.display="block";
}

function previewPopup(template,pg_id)
{
	window.open('../'+template+'?pg_id='+pg_id,'page_preview');
}

function popup(url) {
	window.open(url,'nspopup');
}

function popupSimple(url,w,h)
{
	var hori= w;
	var verti= h;
	var l = (screen.availWidth-hori)/2;
	var t = (screen.availHeight-verti)/2;
	
	if (window.screen)
	{
		window.open(url,'popup'+w+'x'+h, 'width='+hori+', height='+verti+', resize=no, toolbar=no, status=no, menubar=no, scrollbars=yes, left='+(l)+', top='+(t));
		
		//location.href=strPage;
	}
}

function set_div(div_id,html) {
	document.getElementById(div_id).innerHTML=html;
}

function clr_div(div_id) {
	document.getElementById(div_id).innerHTML='';
}

function ns_maximise() {
   window.resizeTo(screen.availWidth,screen.availHeight);
   window.moveTo(0,0);
}

function show_hidden(target) {
	target.style.visibility='visible';
}

function fade_in(id,speed) {
	if (id==this) {
		$(this).fadeIn(speed);
	} else {
		$('#'+id).fadeIn(speed);
	}
}

function fade_out(id,speed) {
	if (id==this) {
		$(this).fadeOut(speed);
	} else {
		$('#'+id).fadeOut(speed);
	}
}

var menu_current=1;

function menu_focus(i) {
	document.getElementById('menu_btn_'+i).className='menu_btn_over';		
}

function menu_blur(i) {
	if (i==menu_current) {
		document.getElementById('menu_btn_'+i).className='menu_btn_down';
	} else {
		document.getElementById('menu_btn_'+i).className='menu_btn_up';
	}
}

function menu_down(i) {
	document.getElementById('menu_btn_'+i).className='menu_btn_click';
}

function menu_up(i,page) {
	if (i!=menu_current) {
		document.getElementById('menu_btn_'+menu_current).className='menu_btn_up';
	}
	document.getElementById('menu_btn_'+i).className='menu_btn_down';
	menu_current=i;
	top.document.getElementById('content_iframe').src='ns_page.php?page='+page;
}

function set_menu(i) {
	if (i!=menu_current) {
		document.getElementById('menu_btn_'+menu_current).className='menu_btn_up';
	}
	document.getElementById('menu_btn_'+i).className='menu_btn_down';
	menu_current=i;
}

function home_window_focus(i) {
	if (i!=window_current) {
		document.getElementById('home_window_'+window_current).className='home_window_pointer_up';
		document.getElementById('home_window_img_'+window_current).style.display='none';
	}
	document.getElementById('home_window_'+i).className='home_window_pointer_over';
	document.getElementById('home_window_img_'+i).style.display='block';
	window_current=i;
}

function home_window_blur(i) {
//	document.getElementById('home_window_'+i).className='home_window_pointer_up';
}

function home_window_up(i,page,pg_id) {
	document.getElementById('home_window_'+i).className='home_window_pointer_over';
	window_current=i;
	top.menu_up(pg_id,page);
	top.document.getElementById('content_iframe').src=page;
}

function prev_focus(id) {
	document.getElementById(id+'_img').src=prev_src_over;
	document.getElementById(id).className='paging_link_over';
}

function prev_blur(id) {
	document.getElementById(id+'_img').src=prev_src;
	document.getElementById(id).className='paging_link';
}

function next_focus(id) {
	document.getElementById(id+'_img').src=next_src_over;
	document.getElementById(id).className='paging_link_over';
}

function next_blur(id) {
	document.getElementById(id+'_img').src=next_src;
	document.getElementById(id).className='paging_link';
}

function upload_focus(id) {
	document.getElementById(id+'_img').src=upload_src_over;
	document.getElementById(id).className='paging_link_over';
}

function upload_blur(id) {
	document.getElementById(id+'_img').src=upload_src;
	document.getElementById(id).className='paging_link';
}

var playlist_current=1;
var playlist_src = new Array();

function playlist_focus(id) {
	document.getElementById('playlist_'+id).className='playlist_link_over';
}

function playlist_blur(id) {
	if (id==playlist_current) {
		document.getElementById('playlist_'+id).className='playlist_link_over';
	} else {
		document.getElementById('playlist_'+id).className='playlist_link';
	}
}

function playlist_click(id) {
	document.getElementById('playlist_'+playlist_current).className='playlist_link';
	document.getElementById('playlist_'+id).className='playlist_link_over';
	playlist_current=id;
	jwplayer("playlist_player").load({file: playlist_src[id] });
}

function playlist_next(id) {
	playlist_next=playlist_current+1;
	if (playlist_next>playlist_n) {
		playlist_next=1;
	}
	playlist_click(playlist_next);
}

var p_max = 9;
var p_n = new Array();
var p_current = new Array();
var p_start = new Array();
var p_end = new Array();

				 
function i_focus(e) {
	e.className='index_number_current';
}

function i_blur(e,label,i) {
	if (i!=p_current[label]) {
		e.className='index_number';
	}
}

function i_click(label,change,i) {
	n=p_n[label];
	start=p_start[label];
	end=p_end[label];
	current=p_current[label];
	//prev/next
	if (change!=0) {
		target=current+change;
		if (target>end) {
			if (target>n) {
				target=1;
				start=1;
				end=n;
				if (end>p_max) {
					end=p_max;
				}
			} else {
				start++;
				end++;
			}
		} else {
			if (target<start) {
				if (target==0) {
					target=n;
					end=n;
					start=1;
					if (n>p_max) {
						start=n-p_max+1;
					}
				} else {
					start--;
					end--;
				}
			}
		}
		
		if ((change==1) && (target==end) && (end<n)) {
			start++;
			end++;
		}
		if ((change==-1) && (target==start) && (start>1)) {
			start--;
			end--;
		}
	}
	//index
	if (i!=0) {
		target=i;
		if (target==end) {
			if (end<n) {
				start++;
				end++;
			}
		}
		if (target==start) {
			if (start>1) {
				start--;
				end--;
			}
		}
	}
	//update status
	x=0;
	while (x<n) {
		x++;
		if ((x<start) || (x>end)) {
			document.getElementById(label+'_index_number_'+x).className='index_number_hidden';
		} else {
			document.getElementById(label+'_index_number_'+x).className='index_number';
		}
	}
	document.getElementById(label+'_index_number_'+target).className='index_number_current';
	$('#'+label+'_links_container').cycle((target-1));  
	p_start[label]=start;
	p_end[label]=end;
	p_current[label]=target;
}

function detail_set(src) {
	document.getElementById('detail_iframe').src=src;

}

function show_paging_wrappers() {
	if (document.getElementById('left_paging_wrapper')) {
		document.getElementById('left_paging_wrapper').style.display='block';
	}
	if (document.getElementById('right_paging_wrapper')) {
		document.getElementById('right_paging_wrapper').style.display='block';
	}
	if (document.getElementById('jukebox_paging_wrapper')) {
		document.getElementById('jukebox_paging_wrapper').style.display='block';
	}
}

function goto(page,pg_id) {
	top.document.getElementById('content_iframe').src=page;
	if (pg_id!=top.menu_current) {
		top.document.getElementById('menu_btn_'+menu_current).className='menu_btn_up';
	}
	top.document.getElementById('menu_btn_'+pg_id).className='menu_btn_down';
	top.menu_current=pg_id;
//	top.document.getElementById('content_iframe').src='ns_page.php?page='+page;
}

function link_over(id) {
	document.getElementById(id).className='link_details_over';
}
function link_out(id) {
	document.getElementById(id).className='link_details';
}

function window_goto(id) {
    $('#home_window_content').cycle(id); 
   	return false; 
}

function window_thumbs_next() {
	$("#home_window_thumbs").trigger("next", 1);
}

function window_thumbs_prev() {
	$("#home_window_thumbs").trigger("prev", 1);
}

function pageable_detail_move(dir) {
	if (dir!=0) {
		target=p_detail_current+dir;
		if (target>(p_detail_n-1)) {
			$("#pageable_detail_btn_"+target).hide("fast");
		}
	}
	if (dir==0) {
//		$("#pageable_detail_btn_"+p_detail_current).show("fast");
		$("#pageable_detail_"+p_detail_current).hide("fast");
		$("#pageable_detail_back").hide("fast");
		if (p_detail_n>1) {
			$("#pageable_detail_next").show("fast");
		}
		target=0;
		p_detail_current=0;
	}
	if (target>0) {
		$("#pageable_detail_prev").show("fast");
	}
	if (target==0) {
		$("#pageable_detail_prev").hide("fast");
	}
	if (target==(p_detail_n-1)) {
		$("#pageable_detail_next").hide("fast");
	}
	if (target<(p_detail_n-1)) {
		$("#pageable_detail_next").show("fast");
	}
	$("#pageable_detail_"+p_detail_current).hide("fast");
	$("#pageable_detail_"+target).show("fast");
	p_detail_current=target;
}

function pageable_detail_show(target) {
//	if (target!=p_detail_current) {
//		$("#pageable_detail_btn_"+p_detail_current).show("fast");
//	}
	$("#pageable_detail_prev").hide("fast");
	$("#pageable_detail_next").hide("fast");
//	$("#pageable_detail_btn_"+target).hide("fast");
	$("#pageable_detail_"+p_detail_current).hide("fast");
	$("#pageable_detail_"+target).show("fast");
	$("#pageable_detail_back").show("fast");
	p_detail_current=target;
}

function j_focus(id) {
	if (id!=j_current) {
		if (j_current!=j_playing) {
			$("#jukebox_link_"+j_current).removeClass("jukebox_link_over").addClass("jukebox_link");
		}
		$("#jukebox_link_"+id).removeClass("jukebox_link").addClass("jukebox_link_over")
		j_current=id;
	}
}

function j_click(id) {
	if (id!=j_playing) {
		$("#jukebox_link_"+j_playing).removeClass("jukebox_link_over").addClass("jukebox_link");
	}
	j_current=id;
	j_playing=id;
}
