var alldata = {};
var alldatalookup = {};
var viewstack = [];
var viewstackitemdone = true;
var renders = {};
var nextindex = 150;
var refarr = {};
var XXX = 0;
var YYY = 0;
var ytplayer = null;
var doctitlebase = "";
var pageTracker = null;
var testfor = null;
var blogonloadid = -1;
var oldblogfocusindex = -1;
var blogfocusindex = 0;
var blogarr = [];
var blogsubid = 0;
var arrissat = 0;
var allblogarr = [];
var curcati = -1;
var oldfull = 0;
var youtubes = [];
var youtubechecker = null;
var istop = 0;
var previd = 0;
var galboxarr = [];
var istopsub = 0;
var vloks = {};

jQuery(document).ready(function($) {
	startit();
	});

function startit(){
	doctitlebase = document.title;
	testfor = setInterval(function() {
		if (pageTracker === null) {
			try {
				pageTracker = _gat._getTracker("UA-3579325-14");
				pageTracker._initData();
				pageTracker._trackPageview();

			} catch (err) {
			}
		} else {
			clearInterval(testfor);
		}
	}, 500);

	$(document).mousemove(function(e) {
		XXX = e.pageX
		YYY = e.pageY;
	});
	docufon();
	hookups();

	$("#logo").fadeIn(500, function(e) {
	});
	$("#menu").fadeIn(600, function(e) {
	});
	$("#underpage").fadeIn(6000);
	$.ajax( {
		url : "/?buildjscache2=1",
		global : false,
		type : "GET",
		data : ( {
			"test" : "test"
		}),
		dataType : "json",
		success : prepdata
	});
	
	
	}	
	

function prepdata(data) {
	prepdata2(data);
	conti();
	
}
	var skipiid = -1;
	var skipiidsub = -1;

function conti(){
	
	var ooo = window.location.href.split("#");
	var ur = ooo.shift();
	if (ooo.length) {
		var name = ooo.shift();
		skipiid = rootidname(name);
		skipiidsub = vloks[name];
		if (skipiid == skipiidsub) {
			skipiidsub = -1;
		}
	}
	var d = alldatalookup;
	var s = "";
	var tmp = [];
	for ( var i in d) {
		if (i != skipiid) {
			tmp.push(d[i]);
		}
	}
	/*
	 * tmp.sort(function(a, b) { if (a.menu_order < b.menu_order) { return -1; }
	 * else { if (a.menu_order > b.menu_order) { return 1; } else { return 0; } }
	 * });
	 */

	tmp.sort(function(a, b) {
		var ta = parseInt(a.metas.loaderorder);
		var tb = parseInt(b.metas.loaderorder);

		if (ta < tb) {
			return -1;
		} else {
			if (ta > tb) {
				return 1;
			} else {
				return 0;
			}
		}
	});

	d = {};
	var arrtmp = []
	for ( var i in tmp) {
		d[tmp[i].ID] = tmp[i];
		arrtmp.push(tmp[i].ID);
	}
	for ( var i in d) {
		s += menuline(d[i]);
	}

	// $("#menuinner").html(s);

	// $("#menuinner").css({top: 200px});
	// $("#menuinner").animate({"height": "122px"}, 2250, 'swing');

	// arrtmp = $.shuffle(arrtmp);

	var cll = $("body").attr('class');
	if (cll.indexOf(" home") > -1) {
		for ( var i in arrtmp) {
			if (refarr[arrtmp[i]].post_name === "film") {

			} else {
			}
			queload(arrtmp[i], function(e) {
			});
		}
	} else {

		var arr = cll.split(" ");
		if (arr.length > 5) {
			var tt = arr[5];
			if (tt == "category") {
				$("#content").html('');
				$("#sidebar").html('');
			}
			if (arr[6] == "single") {
				var ss = window.location.href;
				window.location = ss.replace(bdir, bdir + "/#");
			}

			// lpbyname(tt);

		}

	}
	if (skipiid == 122) {
		blogonloadid = skipiidsub;
	}

	queload(skipiid, function(e) {
		if (skipiidsub !== skipiid) {
			if (skipiid == 122) {
				blogonloadid = skipiidsub;
			} else {
				subpage(skipiid, skipiidsub);
			}
		}

		var oldi = window.location.href;

		setInterval(function() {
			if (oldi != window.location.href) {
				oldi = window.location.href;
				var ooo = oldi.split("#");
				var ur = ooo.shift();
				if (ooo.length) {
					var name = ooo.shift();
					skipiid = rootidname(name);
					skipiidsub = vloks[name];
					if (skipiid == skipiidsub) {

					} else {
	
	
				if (typeof (skipiid) != undefined) {

					if (typeof (skipiidsub) != undefined) {
						if (skipiid !== skipiidsub) {
							if (skipiid == 122) {
								// blog
								blogonloadid = skipiidsub;
								renderadd(refarr[122]);
							} else {
								/* blogonloadid = -1; */
								subpage(skipiid, skipiidsub);

							}
						} else {
							renderadd(refarr[skipiid]);
						}

					} else {
						if (skipiid != istop) {
							renderadd(refarr[skipiid]);

						}
					}

				}

			}

		}

		// $("body").append(skipiid+":"+skipiidsub+"<br>");
	}

}, 500	);

	});

	queexe_interval = setInterval(queexe, 245);

	// hookups();

	
	}
var redirecttos = {};
function prepdata2(data) {
	for ( var i in data.cats) {
		vloks['category/' + data.cats[i].slug] = 122;
	}
	alldata = data;
	
	alldata.cats.sort(function(a,b){
		if(a.sortorder > b.sortorder){
			return 1;
		}else if(a.sortorder<b.sortorder){
			return -1;			
			}else{
				return 0;
			}
		});
	
	var s = "";
	var dd = alldata.data;
	var conv = [];
	for ( var p in dd) {
		var o = {};

		for ( var i in alldata.model) {
			o[i] = dd[p][alldata.model[i]];
		}
		conv.push(o);
	}
	dd = conv;
	var orfs = [];
	while (dd.length) {
		var vu = dd.shift();
		refarr[vu.ID] = vu;
		if (vu.post_parent == 0) {
			alldatalookup[vu.ID] = vu;
			vloks[vu.post_name] = vu.ID
			if(vu.metas && vu.metas.redirectto){
				redirecttos[vu.post_name] = vu.metas.redirectto;
				}
			
			
		} else {
			if (alldatalookup[vu.post_parent]) {
				if (!alldatalookup[vu.post_parent].children) {
					alldatalookup[vu.post_parent].children = [];
				}
				alldatalookup[vu.post_parent].children.push(vu);
				vloks[alldatalookup[vu.post_parent].post_name + "/"
						+ vu.post_name] = vu.ID

			} else {
				// dd.push(vu);
				orfs.push(vu);
			}
		}
	}
	dd = orfs;
	var orfs2 = [];
	while (dd.length) {
		var vu = dd.shift();
		refarr[vu.ID] = vu;
		if (vu.post_parent == 0) {
			alldatalookup[vu.ID] = vu;
			vloks[vu.post_name] = vu.ID
		} else {
			if (alldatalookup[vu.post_parent]) {
				if (!alldatalookup[vu.post_parent].children) {
					alldatalookup[vu.post_parent].children = [];
				}
				alldatalookup[vu.post_parent].children.push(vu);
				vloks[alldatalookup[vu.post_parent].post_name + "/"
						+ vu.post_name] = vu.ID

			} else {
				// dd.push(vu);
				orfs2.push(vu);
			}
		}
	}

	
}

function rootidname(name) {
	var arr = name.split("/");
	var root = arr.shift();
	return vloks[root];
}
function lpbyname(name) {
	var arr = name.split("/");
	var root = arr.shift();
	var fp = arr.join("/");
	if (vloks[fp]) {
		
		if(redirecttos[fp]){
	
			subpage(vloks[fp],redirecttos[fp]);	
			
			focusit(vloks[fp],redirecttos[fp]);
 			
			}else{

		renderadd(refarr[vloks[fp]], function(da) {
			focusit(vloks[fp]);
			scroll(0, 0);
				return false;

			});

				
				}
		

	}
	return false;

}

function hookup_aimg1() {
	$("a img.dlreplace")
			.each(
					function(e) {
						if ($(this).attr('issat')) {
						} else {
							$(this).attr('issat', "1");
							var t = $(this).parent();
							var href = t.attr('href');
							t = t.parent();
							var src = $(this).attr('src');
							var s = '<div class="piccax" style="background-image: url(' + src + '); width: 320px; height: 290px;">';
							s += '<div class="picca">';
							s += '<h5>Download Hi-Res</h5>'
							s += '</div>';
							s += '</div>';

							t.html(s);
							t.hover(function(e) {
								$("DIV.picca").css( {
									"display" : "block"
								});

							}, function(e) {
								$("DIV.picca").css( {
									"display" : "none"
								});
							});

							t.click(function(e) {
								window.location.href = href;
							});

						}

					});

}

function hookup_alla() {
	$("a").each(function(e) {
		if ($(this).attr("issat")) {

		} else {
			$(this).attr("issat", "1");
			var link = $(this).attr("href");
			if (link.substring(0, bdir.length).toLowerCase() === bdir) {
				// internal
			link = link.substring(bdir.length);
			// href="javascript:lpbyname('"+link+"');";
			$(this).click(function(e) {
				lpbyname(link);
				return false;
			});
		} else {
			if (link.substring(0, 7).toLowerCase() == "http://") {
				// outside;
				link = link;
			} else {

			}
		}
		// ss+=(link+"<br>");
	}
}	);

}

function hookup_blog() {
	// if(blogarr.length < 1){
	// }
	// blog_render();
	if (arrissat == 0) {

		$('#blogcontent').each(function() {
			arrissat = 1;
			var idd = $(this).attr('val');
			var arr = [];
			for ( var i in refarr) {
				if (refarr[i]['post_parent'] == idd) {
					arr.push(i);
				}
			}
			
			
			arr.sort(function(a,b){
				var aa = refarr[a].post_date;
				var bb = refarr[b].post_date;
				if(aa > bb){
					return -1;
				}else if(aa<bb){
					return 1;
					}else{
						return 0;
				}
				});

			blogarr = arr;
			allblogarr = arr;
			for ( var i in blogarr) {
				if (blogarr[i] == blogonloadid) {
					blogfocusindex = parseInt(i);
				}
			}
			$("#post-" + idd).css( {
				height : 'auto'
			});

		});

	} else {
		$('#blogcontent').each(function() {
			var idd = $(this).attr('val');
			$("#post-" + idd).css( {
				height : 'auto'
			});
		});

	}
	blog_render();

}

function hookups() {
	hookup_aimg1(); /* for press section hires download */
	hookup_blog();
	hookup_alla(); /* convert all internal links to js */

	$('.csvtable').each(function() {
		if ($(this).html() == "") {

			var nam = $(this).attr('src');
			$(this).html('<div id="testa"></div>');
			$("#testa").csv2table(nam, {
				nowloadingMsg : "Loading..."
			});

		}
	});

}

function blog_navi() {
	var s = "";
	s += '<div class="navi">';

	if (blogfocusindex > 0) {
		s += '<div class="navib blog_prev">NEWER »</div>';
	} else {
		s += '<div class="navib ">&nbsp;</div>';
	}

	if (blogfocusindex < blogarr.length - 5) {
		s += '<div class="navib blog_next">« OLDER</div>';
	} else {
		s += '<div class="navib blog_a">&nbsp;</div>';
	}

	if (blogarr.length > 1) {
		s += '<div class="navis">PAGE ' + (Math.floor(blogfocusindex/posts_per_page) + 1) + ' of '
				+ (Math.ceil(blogarr.length/posts_per_page)) + '</div>';
	}

	s += '<div style="clear: both;"></div>';

	s += '</div>';
	return s;
}
function blog_show(cati) {
	curcati = cati;
	blogarr = alldata.cats[cati].posts;
	blogfocusindex = 0;
	blogonloadid = blogarr[0];
	oldblogfocusindex = -1;
	blog_render();
	laytop(122, -1);
}
function blog_show_all() {
	curcati = -1;
	blogarr = allblogarr;
	blogfocusindex = 0;
	blogonloadid = blogarr[0];
	oldblogfocusindex = -1;
	blog_render();
	laytop(122, -1);
}

function trackit(u) {
	if (pageTracker) {
		pageTracker._trackPageview(u);
	}
}


function render_a_blog_post(){
	
	
	}

var posts_per_page=5;
function blog_render() {
	$('#categoryselector').each(
			function() {
				var d = alldata.cats;	


				var s = '<div class="mentry">';
					s += '<li class="page_item '
							+ (curcati == -1 ? 'selected' : '')
							+ '"><a href="javascript:blog_show_all();">All</a></li>';

				for ( var i in d) {
					/*
					 * s += '<li class="page_item"><a href="' + bdir +
					 * '/category/' + d[i].slug + '" title="' + d[i].name + '">' +
					 * d[i].name + '</a></li>';
					 */
					s += '<li class="page_item '
							+ (curcati == i ? 'selected' : '')
							+ '"><a href="javascript:blog_show(' + i + ');">'
							+ d[i].name + '</a></li>';
				}
				s += '</div>';
				$(this).html(s);

			});
	var mmi=posts_per_page;

	if(blogfocusindex > blogarr.length){
		blogfocusindex = blogarr.length-posts_per_page;
		mmi = posts_per_page;
	} 
	if(blogfocusindex < 0){
		blogfocusindex = 0;
		mmi = posts_per_page;
		}
		if(blogfocusindex+mmi > blogarr.length){
			mmi = blogarr.length-blogfocusindex;
			}



	if ((blogfocusindex != oldblogfocusindex || $('#blogcontent').html() == "xxx")
			&& blogarr[blogfocusindex] && refarr[blogarr[blogfocusindex]]) {
		oldblogfocusindex = blogfocusindex;
		var s = "";

		var ss = '<div id="actualblog">';
			for(var iii = 0;iii<mmi;iii++){
				var ts = refarr[blogarr[blogfocusindex+iii]].thumba;
					if (ts.indexOf('<object') > -1
							&& ts.indexOf('<param name="wmode" value="opaque">') == -1) {
						var t = ts.split('<param');
						var to = t.shift();
						t.unshift(' name="wmode" value="opaque">');
						t.unshift(to);
						ts = t.join('<param');
					}
					if (ts.indexOf('wmode=') == -1) {
						ts = ts.replace('<embed ', '<embed wmode="opaque" ');
					}

				ss += ts;

			}
			
			ss += "</div>";

			
		s += ss;
		s += blog_navi();
		$('#blogcontent').html(s);

		if (ss.indexOf('<object') > -1) {
			$('object', '#blogcontent').each(function() {

					// var t = $(this).clone();
					$(this).wrap('<div class="videostar" />');

					// $(this).replaceWith('<div></div>');
					// $(this).append('adafasdfa');

				});
		}

		// $(".videostar").css({'z-index':1,position: 'relative'});

		$(".navib").hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});

		$('.blog_next').click(function() {
			scroll(0, 0);
			blog_next();
		});
		$('.blog_prev').click(function() {
			scroll(0, 0);
			blog_prev();

		});

		$('.shareable', '#blogcontent').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});

		$('.shareable', '#blogcontent').each(function(){
			var id = $(this).attr('val');
			$(this).after('<div id="sharer-'+id+'"></div>');
			});

		$('.shareable', '#blogcontent')
				.click(function() {
					var val = $(this).attr('val');
					// $(this).html('SHARE : <div>Facebook</div>
						// <div>Twitter</div> <div>Print</div>
						// <div>Email</div>');
						$('#sharer-'+val)
								.html(
										'<div onclick="blog_fb_share('
												+ val
												+ ');">Facebook</div> <div onclick="blog_twitter_share('
												+ val
												+ ');">Twitter</div> <div onclick="blog_print_share('
												+ val
												+ ');">Print</div> <div onclick="blog_email_share('
												+ val + ');">Email</div>');

						$('div', '#sharer-'+val).hover(function() {
							$(this).addClass('hover');
						}, function() {
							$(this).removeClass('hover');
						});

					});

	}
	hookup_alla();

}

function blog_fb_share(pid) {
	var u = bdir + '/#blog/' + refarr[pid].post_name;
	var t = refarr[pid].post_title;
	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u)
			+ '&t=' + encodeURIComponent(t), 'fbsharer',
			'toolbar=0,status=0,width=626,height=436');
}
function blog_twitter_share(pid) {
	var u = bdir + '/#blog/' + refarr[pid].post_name;
	var t = refarr[pid].post_title;
	var twtLink = 'http://twitter.com/home?status=' + encodeURIComponent(t
			+ ' ' + u);
	window.open(twtLink, 'twittersharer', '');
}

function blog_print_share(pid) {
	var tt = window.open('about:blank', 'print', '');
	tt.document.write($("#actualblog").html());
}
function blog_email_share(pid) {
	var u = bdir + '/#blog/' + refarr[pid].post_name;
	var t = refarr[pid].post_title;
	var cc = [];
	cc[0] = "mailto:";
	cc[1] = encodeURIComponent('@');
	cc[2] = "?subject=";
	cc[3] = encodeURIComponent(t);
	cc[4] = "&body=";
	cc[5] = encodeURIComponent(t + "\n\n" + u);
	window.location = cc.join("");

}

function blog_next() {
	blogfocusindex += posts_per_page;
	blog_render();
	laytop(122, -1);
}
function blog_prev() {
	blogfocusindex -= posts_per_page;
	blog_render();
	laytop(122, -1);
}

function menuline(p) {
	var s = '<a title="' + p.post_title + '" href="/' + p.post_name
			+ '" onclick="return rootpage(\'' + p.ID + '\');">' + p.post_title
			+ '</a> ';
	return s;
}
function rootpage(t) {
	queload(t, function(e) {
		return false;
	});
	return false;
}
function queload(t, callback) {
	if (typeof (callback) != "function") {
		callback = function(e) {
			return e
		};
	}
	viewstack.push( [ t, callback ]);
}

var queexe_interval = null;
var queexe_timeout = 10;
function queexe() {
	if (viewstack.length && viewstackitemdone) {
		viewstackitemdone = false;
		var t = viewstack.shift();
		var d = alldatalookup[t[0]];
		renderadd(d, function() {
			viewstackitemdone = true;
			t[1](d);
		});
	}else{
		
		if(viewstack.length===0){

			if(queexe_timeout -- < 0 || viewstackitemdone){
				clearInterval(queexe_interval);
				donedone();
				}
				
		}
	}
}

function donedone(){
	//alert("::"+skipiid+":"+skipiidsub);
	if(skipiid>-1){
		focusita(skipiid,skipiidsub);	
		
	}else{
			focusita(istop,istopsub);	


		
		}
	
	}
function focusita(id,idsub){
	for(var i in renders){
		if(i==id){
				renders[i].css({'display':'block'});
				$("#menuinner li.page-item-"+i+"").addClass("selected");
			}else{
				$("#menuinner li.page-item-"+i+"").removeClass("selected");
				$("#bgstuffdiv-"+i).remove();
				//renders[i].css({'display':'none'});
			}
		}
		docufon();
		
}	

function focusit(id,idsub){
	for(var i in renders){
		if(i==id){
				renders[i].css({'display':'block'});
				$("#menuinner li.page-item-"+i+"").addClass("selected");
			}else{
				$("#menuinner li.page-item-"+i+"").removeClass("selected");
				$("#bgstuffdiv-"+i).remove();
				renders[i].css({'display':'none'});
			}
		}
		docufon();
		
}	
	
function renderadd2(d, callback) {
	if(typeof(d)==="undefined"){
		return false;
		}


	istop = d.ID;
	/*
	 * if (renders[d.ID]) { var x = Math.floor(Math.random() * 100); var y =
	 * Math.floor(Math.random() * 100); renders[d.ID].css( { 'z-index' :
	 * nextindex }); nextindex++; } else {
	 */
	var nholder = '<div id="holder-' + d.ID + '"><div id="abg-'+d.ID+'"></div>' + d.thumba + '</div>';
	if ($("#holder-" + d.ID).html() != null) {
		$("#holder-" + d.ID).html(d.thumba);
	} else {
		$("#wrap").append(nholder);

	}

	$("#holder-" + d.ID).css( {
		position : "fixed",
		top : '80px',
		width : '980px',
		height : '10px',
		margin : "auto",
		display : 'none',
		'z-index' : nextindex
	});
	nextindex++;
	renders[d.ID] = $("#holder-" + d.ID);
	/* } */

	$("#overs").html('').css( {
		display : "none"
	});
	$("#singleovers").html('').css( {
		display : "none"
	});
	// $("#bgstuff").html('');

	$("#post-" + d.ID + "").click(function(event) {
		laytop(d.ID, -1);
		event.stopPropagation();
		$(this).mouseleave();
		});

	if (d.metas) {
		var cob = {};
		if (d.metas.bgcolor) {
			cob['background-color'] = d.metas.bgcolor[0];
			$("#post-" + d.ID + "").hover(function(e) {
				if (istop !== d.ID) {
					$(this).css( {
						'background-color' : "#ffffff",
						'cursor' : "pointer"
					});
				} else {
					$(this).css( {
						'cursor' : "default"
					});

				}
			}, function(e) {
				$(this).css( {
					'background-color' : d.metas.bgcolor[0],
					'cursor' : "none"

				});
			});
		}
		if (d.metas.left) {
			cob['left'] = d.metas.left[0] + "px";
		}
		if (d.metas.top) {
			cob['top'] = d.metas.top[0] + "px";
		}
		if (d.metas.width) {
			cob['width'] = d.metas.width[0] + "px";
		}
		if (d.metas.height) {
			cob['height'] = d.metas.height[0] + "px";
		}
		if (d.metas.color) {
			cob['color'] = d.metas.color[0];
		}

		$("#post-" + d.ID + "").css(cob);

		if (d.metas.bgimage) {
			var bs = "";
			bs += '<div id="bgstuffdiv-'+d.ID+'" style="background-image: url(' + d.metas.bgimage[0] + '); left: 100px; top: 0px;"></div>';
			$("#bgstuff").html(bs);
			$("#bgstuff").css( {
				'z-index' : (nextindex - 1)
			});
 
		}

		var links = [];
		$("#holder-" + d.ID + " a").each(function() {
			var urli = $(this).attr('href');
			if (urli.indexOf("http://youtube.com/v/") > -1) {
				links.push( {
					id : urli.replace("http://youtube.com/v/", ""),
					title : $(this).text()
				});
			}
		});

		if (links.length > 0) {

			/**
			 * <object width="560" height="340"><param name="movie"
			 * value="http://www.youtube.com/v/4rjqcGHSQXA&hl=en_US&fs=1&rel=0"></param><param
			 * name="allowFullScreen" value="true"></param><param
			 * name="allowscriptaccess" value="always"></param><embed
			 * src="http://www.youtube.com/v/4rjqcGHSQXA&hl=en_US&fs=1&rel=0"
			 * type="application/x-shockwave-flash" allowscriptaccess="always"
			 * allowfullscreen="true" width="560" height="340"></embed></object>
			 */
			youtubes = links;

			$("#post-" + d.ID)
					.html(
							'<div id="ytover"><div id="ytPlayer"></div><div id="ytControls">'
									+ '<div id="ytPlay" class="ele"></div><div id="ytStop" class="ele"></div><div id="ytCount" class="ele"></div>'
									+ '<div id="ytBar" class="ele"></div><div id="ytRemain" class="ele"></div><div id="ytMute" class="ele"></div>'
									+ '<div id="ytVolume" class="ele"></div><div id="ytFullscreen" class="ele"></div><div id="ytLink"></div>'
									+ '</div><div id="ytPlayerMeta"></div></div><div id="ytPlayerPreviews"></div>');

			loadPlayer();

			$("#ytControls .ele").hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});

			$("#ytPlay").click(function() {
				ytplayer.playVideo();

			});
			$("#ytStop").click(function() {
				ytplayer.pauseVideo();
			});

			$("#ytLink").click(function() {
				ytplayer.pauseVideo();
				var nw = window.open(ytplayer.hurl, '_blank');
			});

			$("#ytFullscreen").click(function() {
				var ww = $(window).width();
				var hh = $(window).height();

				if ($("#ytover").css('z-index') == 2010) {

					$("#ytover").css( {
						position : 'fixed',
						'z-index' : 100,
						'left' : ((ww / 2)) + 'px',
						'top' : '0px',
						'width' : "640px",
						'height' : '360px'
					});
					$("#menu").css( {
						'display' : 'block'
					});

				} else {

					$("#menu").css( {
						'display' : 'none'
					});
					$("#ytover").css( {
						position : 'fixed',
						top : '0px',
						left : '0px',
						'z-index' : 2010,
						'width' : ww + "px",
						'height' : hh + 'px'
					});
					$("#ytPlayer").css( {
						'width' : '100%',
						'height' : '100%'
					});

				}


				});

			$("#ytMute")
					.click(
							function() {
								if (ytplayer.getVolume() > 0) {
									ytplayer.setVolume(0);
									$(this)
											.css(
													{
														background : 'url(/wp-content/themes/mn/player/sound_off.png) no-repeat center center #000'
													});

								} else {
									ytplayer.setVolume(30)
									$(this)
											.css(
													{
														background : 'url(/wp-content/themes/mn/player/sound_on.png) no-repeat center center #000'
													});

								}
								;
							});

			var ww = $(window).width();

			$("#ytover").css( {
				'position' : 'fixed',
				'width' : '640px',
				'height' : '360px',
				'top' : '0px',
				'left' : (ww / 2) + 'px'

			});

			$("#ytover").css( {

			});

			$("#ytPlayer").click(function(event) {

				// event.stopPropagation();
					// laytop(d.ID);
				});

			$("#ytPlayerPreviews").css( {

				'padding-top' : '120px',
				'margin-left' : '395px'
			});

			$("#ytPlayerMeta").css( {

			});

		}

	}

	docufon();
	$("#holder-" + d.ID).fadeIn(0, callback);
	hookups();
	laytop(d.ID, -1);

}


function checkfilm2() {
	if (ytplayer) {
		if (youtubes.length > 0) {
			addclip(0, 0);
			clearInterval(youtubechecker);

			var mm = "";
			for ( var i = 0; i < youtubes.length; i++) {
				var uu = 'http://i.ytimg.com/vi/' + youtubes[i].id + '/hqdefault.jpg';
				mm += '<div class="pic" style="background-image: url(' + uu
						+ ');" onclick="addclip(\'' + i + '\',1);"><p>'
						+ youtubes[i].title + '</p></div>';
			}
			$("#ytPlayerPreviews").html(mm);

			$("#ytControls").css( {
				display : 'block'
			})

			$("#ytPlayerPreviews .pic").hover(function() {
				$(this).addClass('hover');

			}, function() {
				$(this).removeClass('hover');

			});

		}
	} else {

	}
}


function renderadd(d, callback) {
	var d = d;

	if (d && d.post_parent && d.post_parent > 0) {
		if (renders[d.post_parent]) {
			subpage(d.post_parent, d.ID);
		} else {
			renderadd(refarr[d.post_parent], function(e) {
				subpage(d.post_parent, d.ID);
			});
		}
	} else {
		renderadd2(d, callback);
	}
}

function docufon() {
	Cufon.replace('h1', {
		fontFamily : 'Mari-Poster'
	});
	Cufon.replace('h2', {
		fontFamily : 'Mari'
	});
	Cufon.replace('h3 a', {
		fontFamily : 'Mari'
	});
	Cufon.replace('#menuinner a', {
		fontFamily : 'Mari',
		hover : {
			color : '#c3beb9'

		}
	});
}


function laytop(ID, SUBID) {
	// $("body").prepend(ID+":"+SUBID+":"+blogfocusindex+" :
	// "+typeof(blogfocusindex)+"<br>");
	istop = ID;
	$("#holder-" + ID).css( {
		'z-index' : nextindex++,
		'position' : 'absolute'
	});
	if (previd == ID) {
	} else {
		$("#holder-" + previd).css( {
			'position' : 'fixed'
		});
	}
	previd = ID;
	$("#overs").html('').css( {
		display : "none"
	});
	$("#singleovers").html('').css( {
		display : "none"
	});
	// $("#bgstuff").html('');
	// scroll(0, 0);
	var d = refarr[ID];
	var link = "";
	link += d.post_name;
	if (SUBID > -1) {
		link += "/" + refarr[SUBID].post_name;
	}
	if (ID == 122 && blogarr[blogfocusindex] && refarr[blogarr[blogfocusindex]]) {
		link += "/" + refarr[blogarr[blogfocusindex]].post_name;
	}
	var ooo = window.location.href.split("#");
	var ur = ooo.shift();
	ur += "#" + link;
	window.location.href = ur;

	if (SUBID > -1) {
		document.title = refarr[SUBID].post_title + " | " + d.post_title
				+ " | " + doctitlebase;
	} else {

		if (ID == 122 && blogarr[blogfocusindex]
				&& refarr[blogarr[blogfocusindex]]) {
			document.title = refarr[blogarr[blogfocusindex]].post_title + " | "
					+ d.post_title + " | " + doctitlebase;

		} else {

			document.title = d.post_title + " | " + doctitlebase;

		}

	}
	trackit(ur);
}


var ssup = {
	'blog' : function(p, c, d) {
		// $("#post-" + p + " .entry").html("sdfasdfasdf");

	},

'collection' : function(p, c, d) {
	if(typeof(d)==="undefined"){
		return false;
		}
	var s = d.thumba;
	var a = s.indexOf('<!--clstart-->') + 14;
	var b = s.indexOf('<!--clstop-->');
	var ss = '<div class="subentry">' + s.substring(a, b) + "</div>";
	ss += '<div style="clear: both;"></div>';
	// $("#post-" + p + " .entry").html(ss);

	$("#post-" + p + " .entry").html(
			'<div id="singleovers"></div><div id="overs">' + ss + '</div>');
	// $("#overs").html(ss);

	var posi = $("#post-3").position();

	$('#overs').css( {
		position : 'relative',
		left : '-80px',
		top : '-190px',
		display : "block"
	});
	$('#overs').click(function(d) {

		$(this).css( {
			display : "none"
		});

	});

	galboxarr = [];
	$(".ngg-gallery-thumbnail-box").each(function() {
		galboxarr.push($(this).attr('id'));
	});

	$("#overs a img")
			.click(function(d) {
				/*
				 * for ( var i in d) { tracet('<pre>' + i + '</pre>'); }
				 */

				var sr = $(this).parent().attr("href");
				var sname = $(this).parent().parent().parent().attr('id');

					var indexq = 0;
					for ( var io = 0; io < galboxarr.length; io++) {
						if (galboxarr[io] == sname) {
							indexq = io;
						}
					}
					// var indexq = galboxarr.indexOf(sname);

					var stitle = $(this).attr('title');
					var astitle = $(this).parent().attr('title');
					var sss = "<div>";
					sss += '<img src="' + sr + '" onclick="$(\'#singleovers\').html(\'\').css({display:\'none\'});">';
					sss += '<div class="navibuts">';
					if (indexq < galboxarr.length - 1) {
						sss += '<div class="nextbut butti" gto="' + galboxarr[indexq + 1] + '"> &raquo; </div>';
					}
					if (indexq > 0) {
						sss += '<div class="prevbut butti" gto="' + galboxarr[indexq - 1] + '"> &laquo; </div>';
					}
					sss += '</div>';

					sss += '<div class="navidesc">';
					sss += '<div class="navidesctitle">';
					sss += stitle;
					sss += '</div>';
					sss += '<div class="navidesctext">';
					sss += astitle;
					sss += '</div>';
					sss += '</div>';
					sss += '</div>';

					$('#singleovers').html(sss);
					/*
					 * $('#singleovers').css( { left : (d.pageX - 225) + 'px',
					 * top : (d.pageY - 200) + 'px', display : "block" });
					 */

					var centerX = ($(window).width() / 2);

					$('#singleovers').css( {

						left : (centerX) + 'px',
						top : '50px',

						display : "block"
					});

					$(".butti").hover(function() {
						$(this).addClass('hover');
					}, function() {
						$(this).removeClass('hover');
					});
					$(".butti").click(function(event) {
						var ss = $(this).attr("gto");
							$("#" + ss + " a img").click();
							event.stopPropagation();

						});

				});

	// var sh = '<h1>' + d.post_title + '</h1>';
	// $("#bgstuff").html(sh);
}

}


function subpage(p, c) {
	var d = refarr[c];
	var dp = refarr[p];
/*	if(c==-1){
		d = refarr[p];
	}*/
	istopsub = c;
	laytop(p, c);
	if (ssup[dp.post_name]) {
		ssup[dp.post_name](p, c, d);
	} else {
		if (d) {
			var s = d.thumba;
			var a = s.indexOf('<!--clstart-->') + 14;
			var b = s.indexOf('<!--clstop-->');
			var ss = '<div class="subentry">' + s.substring(a, b) + "</div>";
			ss = '<h1>' + d.post_title + '</h1>' + ss
					+ '<div style="clear: both;"></div>';
			$("#post-" + p + " .entry").html(ss);
		}
	}

	$(".pagechildren li.page_item").removeClass("selected");
	if(istopsub>-1){
		$(".pagechildren li.page-item-"+istopsub+"").addClass("selected");
	}


	
	hookups();
	docufon();
	// renderadd(d,function(e){
	//	
	// });
	return false;
}

function tracet(m) {
	// $("#debugger").prepend(m);
}




function edump(d, ind) {
	var ind = ind || "";
	var s = "";
	for ( var i in d) {
		if (typeof (d[i]) == "object") {
			s += ind + i + " : \n" + edump(d[i], ind + "\t") + "\n";
		} else {
			s += ind + i + " : " + d[i] + "\n";
		}
	}

	return s;
}
function start_debug() {
	$("body").append('<div id="debug">debug</div>');
	$("#debug").css( {
		'position' : 'absolute',
		'z-index' : 6000,
		'top' : '0px',
		'left' : '0px'
	});
	$("#debug").html('<pre>' + edump( {}) + '</pre>');
}











/*
 * function dds(ss){ var results = [];
 * 
 * var shits = 0; for(var p in alldata['data']){ var ll =
 * alldata['model']['thumba'] ;//alldata['data'][p].length-1; var cats =
 * alldata['data'][p][alldata['model']['cats']]; var tags =
 * alldata['data'][p][alldata['model']['tags']]; if(alldata['data'][p][ll]){ stt =
 * alldata['data'][p][ll].toLowerCase().indexOf(ss); if(stt >-1){
 * results.push([p,stt]); shits += 1; } } } results.sort(general_sort);
 * 
 * return results; }
 */

/*
 * $(".post .inner").hover( function () { $(this).addClass("hover"); }, function () {
 * $(this).removeClass("hover"); } );
 * 
 */
/*
 * $(".cinner .category-tweet .entry-title").each(function(){ var a =
 * $(this).text(); var status = a.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,
 * function(url) { return '<a href="'+url+'" target="_blank">'+url+'</a>';
 * }).replace(/\B@([_a-z0-9]+)/ig, function(reply) { return reply.charAt(0)+'<a
 * href="http://www.twitter.com/'+reply.substring(1)+'"
 * target="_blank">'+reply.substring(1)+'</a>'; }); $(this).html(status); });
 */

/**
 * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
 * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
 * 
 * @param f
 *            onMouseOver function || An object with configuration options
 * @param g
 *            onMouseOut function || Nothing (use configuration options object)
 * @author Brian Cherne <brian@cherne.net>
 */
(function($) {
	$.fn.hoverIntent = function(f, g) {
		var cfg = {
			sensitivity : 7,
			interval : 100,
			timeout : 0
		};
		cfg = $.extend(cfg, g ? {
			over : f,
			out : g
		} : f);
		var cX, cY, pX, pY;
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};
		var compare = function(ev, ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) {
				$(ob).unbind("mousemove", track);
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob, [ ev ]);
			} else {
				pX = cX;
				pY = cY;
				ob.hoverIntent_t = setTimeout(function() {
					compare(ev, ob);
				}, cfg.interval);
			}
		};
		var delay = function(ev, ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob, [ ev ]);
		};
		var handleHover = function(e) {
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement)
					|| e.relatedTarget;
			while (p && p != this) {
				try {
					p = p.parentNode;
				} catch (e) {
					p = this;
				}
			}
			if (p == this) {
				return false;
			}
			var ev = jQuery.extend( {}, e);
			var ob = this;
			if (ob.hoverIntent_t) {
				ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			}
			if (e.type == "mouseover") {
				pX = ev.pageX;
				pY = ev.pageY;
				$(ob).bind("mousemove", track);
				if (ob.hoverIntent_s != 1) {
					ob.hoverIntent_t = setTimeout(function() {
						compare(ev, ob);
					}, cfg.interval);
				}
			} else {
				$(ob).unbind("mousemove", track);
				if (ob.hoverIntent_s == 1) {
					ob.hoverIntent_t = setTimeout(function() {
						delay(ev, ob);
					}, cfg.timeout);
				}
			}
		};
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

(function($) {
	$.fn.shuffle = function() {
		return this.each(function() {
			var items = $(this).children();
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}

	$.shuffle = function(arr) {
		for ( var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x)
			;
		return arr;
	}
})(jQuery);

function updateHTML(elmId, value) {
	document.getElementById(elmId).innerHTML = value;
}

function onPlayerError(errorCode) {

}

function onPlayerStateChange(newState) {
	updateHTML("playerState", newState);
}

// The "main method" of this sample. Called when someone clicks "Run".
function loadPlayer() {
	// Lets Flash from another domain call JavaScript
	var params = {
		allowScriptAccess : "always",
		wmode : "opaque",
		allowFullScreen : "true"
	};

	// The element id of the Flash embed
	var atts = {
		id : "ytPlayer"
	};
	// All of the magic handled by SWFObject
	// (http://code.google.com/p/swfobject/)
	swfobject
			.embedSWF(
					"http://www.youtube.com/apiplayer?"
							+ "&enablejsapi=1&version=3&playerapiid=player1&showsearch=0&rel=0&showinfo=0&showlogo=0&fs=1&hd=1",
					"ytPlayer", "100%", "360", "8", null, null, params, atts);

}

function addclip(yindex, sound) {
	if(ytplayer){
	$("#ytPlayerMeta").html(youtubes[yindex].title);
	ytplayer.cueVideoById(youtubes[yindex].id);
	ytplayer.hurl = 'http://www.youtube.com/watch?v=' + youtubes[yindex].id;
	ytplayer.playVideo();
	if (sound == 1) {
		ytplayer.setVolume(0);
		$("#ytMute").click();
	}
}

}

function onYouTubePlayerReady(playerId) {

	ytplayer = document.getElementById("ytPlayer");
	/*
	 * $("#ytPlayer").css( { 'z-index' : 15 });
	 */

	// This causes the updatePlayerInfo function to be called every 250ms to
	// get fresh data from the player
	// setInterval(updatePlayerInfo, 250);
	// updatePlayerInfo();
	ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
	ytplayer.addEventListener("onError", "onPlayerError");
	// Load an initial video into the player
	// ytplayer.cueVideoById("4rjqcGHSQXA");
	ytplayer.setVolume(0);
	youtubechecker = setInterval(checkfilm2, 250);

}
