/**
 * @author X-PORT
 */

/*------------------------------------ Page Change ------------------------------------*/
$(document).ready(function() {
	$("select[id=pages]").change(function() {
		window.location = $('select[id=pages] option:selected').val();
	});
});

/*------------------------------------ Media Change ------------------------------------*/
$(document).ready(function() {
	$("select[id=category]").change(function() {
		window.location = $('select[id=category] option:selected').val();
	});
});

/*------------------------------------ Tool Tips ------------------------------------*/
$(function() {
	$('.pretty').tooltip( {
		track : true,
		delay : 0,
		showURL : false,
		showBody : " - ",
		extraClass : "pretty",
		fixPNG : true,
		opacity : 0.95,
		left : -120
	});
});

/*------------------------------------ Play Media ------------------------------------*/
$(document).ready(function() {
	$(".media").click(function() {
		var url = $(this).attr("href");
		$('#bgsound').attr("src", url);
		$('#bgsound').attr("src", url);
		return false;
	});
});

/*------------------------------------ CSS Vertical Menu ------------------------------------*/
var menuids = new Array("verticalmenu")
// Enter id(s) of UL menus, separated by commas
var submenuoffset = -2
// Offset of submenus from main menu. Default is -2 pixels.

function createcssmenu() {
	for ( var i = 0; i < menuids.length; i++) {
		var ultags = document.getElementById(menuids[i]).getElementsByTagName(
				"ul")
		for ( var t = 0; t < ultags.length; t++) {
			var spanref = document.createElement("span")
			spanref.className = "arrowdiv"
			spanref.innerHTML = "&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0]
					.appendChild(spanref)
			ultags[t].parentNode.onmouseover = function() {
				this.getElementsByTagName("ul")[0].style.left = this.parentNode.offsetWidth
						+ submenuoffset + "px"
				this.getElementsByTagName("ul")[0].style.display = "block"
			}
			ultags[t].parentNode.onmouseout = function() {
				this.getElementsByTagName("ul")[0].style.display = "none"
			}
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", createcssmenu, false)
else if (window.attachEvent)
	window.attachEvent("onload", createcssmenu)
	
/*------------------------------------ Fix Theme ------------------------------------*/
$(document).ready(function() {
	$(".themeLink").click(function() {
		var ctext = $(this).text();

		$("#ThemeHead").html('Theme >> ' + ctext);
		$("#ThemeCategory").html(themeCat[$(this).attr("href")]);
		return false;
	});
});

$(document).ready(function() {
	$(".charTheme").click(function() {
		var ctext = $(this).text();

		$("#ThemeHead").html('Theme >> ' + ctext);
		return false;
	});
});

$(document).ready(function() {
	$(".pdaLink").click(function() {
		var ctext = $(this).text();

		$("#PDAHead").html('PDA >> ' + ctext);
		$("#PDACategory").html(pdaCat[$(this).attr("href")]);
		return false;
	});
});

$(document).ready(function() {
	$(".otherLink").click(function() {
		var ctext = $(this).text();

		$("#OtherHead").html('ภาพและวีดีโอคลิป Picture & VDO Clip >> ' + ctext);
		return false;
	});
});
/*------------------------------------ Fix Theme ------------------------------------*/
$(document).ready(function(){
    $("a.linkpopup").click(function(){
        var url = this.href;
        var h = 530;
        var w = 600;
        testwindow = window.open(url, 'popup', 'width=' + w + ',height=' + h + ' status=0, toolbar=0, location=0, menubar=0, resizable=0, scrollbars=0');
        
        var sH = document.documentElement.clientHeight;
        var sW = document.documentElement.clientWidth;
        
        var centerH = (sH - h) / 2;
        var centerW = (sW - w) / 2;
        testwindow.moveTo(centerW, centerH);
        
        return false;
    });
});