function get_item(id){
	itm = null;
	if (document.getElementById){
	itm = document.getElementById(id);
	} else if (document.all){
	itm = document.all[id];
	} else if (document.layers) {
	itm = document.layers[id];
	}
	return itm;
}

browserx = '';
browsery = '';
html_content = '';
function browser_size(){

	// for all except IExplorer
	if (self.innerHeight) {
	browserx = self.innerWidth;
	browsery = self.innerHeight;
	
	// IExplorer 6 Strict Mode
	}
	else if (document.documentElement) {

		if( !(browserx = document.documentElement.clientWidth) ) {
			browserx = '1000';
		}
		if( !(browsery = document.documentElement.clientHeight) ) {
			browsery = '700';
		}

	// other IExplorers
	} else if (document.body) {
	browserx = document.body.clientWidth;
	browsery = document.body.clientHeight;
	}
}

browser_size();

function lookforname(testa) {
	florin = testa.name;
		
	if(testa.name == 'wallpaper') {
		var i = 1;
		var item; 

		while(item = get_item('wall' + i) ) {
			
			if(item.className == 'selectedTab') {
				var id_tab_selectat = i;
				break;
			}
			i++;
		}

		if(id_tab_selectat) {
			getCatWallpaper(id_tab_selectat);	
			//getWallpapers(id_tab_selectat);
		}
		else {
			getWallpapers(1);
		}
	}
	else if(testa.name == 'soundconfig') {
		var sound_div = get_item('sound_player_div');
		
		if(sound_div.innerHTML == '') {

// sound_div.innerHTML = "<embed id='sound_player' src='"+ app_web_root+"assets/mp3player2.swf' width='220' height='20' allowfullscreen='true' flashvars='&file=/upload/peterjones_sunshine_lofi.mp3&height=20&width=120&autostart=false'>";

//sound_div.innerHTML = "<embed src='"+ app_web_root +"assets/mp3player.swf' id='sound_player' width='290' height='66' quality='high' type='application/x-shockwave-flash' wmode='window' flashvars='config=%3Cmp3player%20version=%221%22%3E%3Cmusic%20url=%22"+   +"%22%20urlencoded=%22false%22%20volume=%2270%22%20loop=%22false%22%20usecache=%22true%22%20buffer=%224%22%20autoplay=%22false%22%20/%3E%3Clayout%20id=%22custom%22%3E%3Citem%20id=%22playbar%22%20x=%2210%22%20y=%2210%22%20/%3E%3Citem%20id=%22playbutton%22%20x=%2210%22%20y=%2235%22%20/%3E%3Citem%20id=%22stopbutton%22%20x=%2260%22%20y=%2235%22%20/%3E%3Citem%20id=%22volumecontrol%22%20x=%22180%22%20y=%2238%22%20/%3E%3C/layout%3E%3Cstyles%3E%3CBackground%20backgroundColor=%22#CECED5%22%20useBevel=%22true%22%20bevelAlpha=%2270%22%20transparent=%22%22%20/%3E%3CButton%20themeColor=%22#46FF00%22%20useCustom=%22false%22%20customPlayPauseURL=%22%22%20customStopURL=%22%22%20/%3E%3CControlIcons%20backgroundColor=%22#6F7777%22%20/%3E%3CLoadBar%20backgroundColor=%22#FFFFFF%22%20borderColor=%22#C4CCCC%22%20fillColor=%22#5EBB4D%22%20/%3E%3CPlayBar%20backgroundColor=%22#F7F7F7%22%20outerBorderColor=%22#919999%22%20innerBorderColor=%22#C4CCCC%22%20fillColor=%22#7BFF4C%22%20fontSize=%228%22%20color=%22#000000%22%20streamingText=%22Audio Clip - STREAMING%22%20pausedText=%22Audio Clip - PAUSED%22%20width=%22270%22%20/%3E%3CSliderThumbs%20backgroundColorOff=%22#6F7777%22%20backgroundColorOn=%22#46FF00%22%20/%3E%3CUIBorder%20borderColor=%22#666666%22%20borderWidth=%221%22%20/%3E%3CVolumeControl%20themeColorOff=%22#6F7777%22%20themeColorOn=%22#46FF00%22%20/%3E%3C/styles%3E%3C/mp3player%3E' bgcolor='#CECED5'></embed>";
		}
	}
	else if(testa.name == 'report') {
		checkresults('results');
	}
}

function playsound(divId, directory, soundlink) {
	soundlink = app_web_root + directory + soundlink;
	var sound_player = get_item('sound_player');
	//setAttribute('target', '_blank')
 	var flashvars = "&file="+soundlink+"&height=20&width=220&autostart=false";
	var sound_div = get_item(divId);
	sound_div.style.display = '';

sound_div.innerHTML = "<embed id='sound_player' src='"+ app_web_root+"assets/mp3player2.swf' width='320' height='20' allowfullscreen='true' flashvars='&file="+ soundlink +"&height=20&width=320&autostart=true'>";

//var flashvars = "config=%3Cmp3player%20version=%221%22%3E%3Cmusic%20url=%22"+ soundlink +"%22%20urlencoded=%22false%22%20volume=%2270%22%20loop=%22false%22%20usecache=%22true%22%20buffer=%224%22%20autoplay=%22false%22%20/%3E%3Clayout%20id=%22custom%22%3E%3Citem%20id=%22playbar%22%20x=%2210%22%20y=%2210%22%20/%3E%3Citem%20id=%22playbutton%22%20x=%2210%22%20y=%2235%22%20/%3E%3Citem%20id=%22stopbutton%22%20x=%2260%22%20y=%2235%22%20/%3E%3Citem%20id=%22volumecontrol%22%20x=%22180%22%20y=%2238%22%20/%3E%3C/layout%3E%3Cstyles%3E%3CBackground%20backgroundColor=%22#CECED5%22%20useBevel=%22true%22%20bevelAlpha=%2270%22%20transparent=%22%22%20/%3E%3CButton%20themeColor=%22#46FF00%22%20useCustom=%22false%22%20customPlayPauseURL=%22%22%20customStopURL=%22%22%20/%3E%3CControlIcons%20backgroundColor=%22#6F7777%22%20/%3E%3CLoadBar%20backgroundColor=%22#FFFFFF%22%20borderColor=%22#C4CCCC%22%20fillColor=%22#5EBB4D%22%20/%3E%3CPlayBar%20backgroundColor=%22#F7F7F7%22%20outerBorderColor=%22#919999%22%20innerBorderColor=%22#C4CCCC%22%20fillColor=%22#7BFF4C%22%20fontSize=%228%22%20color=%22#000000%22%20streamingText=%22Audio Clip - STREAMING%22%20pausedText=%22Audio Clip - PAUSED%22%20width=%22270%22%20/%3E%3CSliderThumbs%20backgroundColorOff=%22#6F7777%22%20backgroundColorOn=%22#46FF00%22%20/%3E%3CUIBorder%20borderColor=%22#666666%22%20borderWidth=%221%22%20/%3E%3CVolumeControl%20themeColorOff=%22#6F7777%22%20themeColorOn=%22#46FF00%22%20/%3E%3C/styles%3E%3C/mp3player%3E";

//sound_player.setAttribute('flashvars', flashvars);

}

function testTimeout(a) {
	var item = get_item('innerpanel1');
	YAHOO.example.container.wait.hide();
	item.innerHTML = html_content;

	replaceChecks();
}

function getPanels() {
	
	var handleSuccess = function(o){
		if(o.responseText !== undefined){

			yuimainpanel.show();
			html_content = o.responseText;
			setTimeout("testTimeout(html_content);", 550);
		}
	}

	var handleFailure = function(o){
		if(o.responseText !== undefined){
		}
	}
	
	var sUrl = app_web_root + "panels/"; 
	var callback =
		{
		  success:handleSuccess,
		  failure:handleFailure,
		  argument: { foo:"foo", bar:"bar" }
		};
	
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
}

var slider1; 
var slider2;

function sliderInit() {

	var startValue = 77;
	yslider1 = YAHOO.widget.Slider.getVertSlider("sliderbg1", "sliderthumb1", 0, 100);
	yslider1.setValue(77);
        yslider1.subscribe("change", function(offsetFromStart) {
		var test2 = get_item('sliderbg1');
                var test1 = get_item('sliderthumb1');
		var inputval = get_item('vertVal1');

		if(!test1.style.top) {
			//test1.style.top = startValue;
			inputval.value = startValue;
		}
		else {
			inputval.value = 100 - (parseInt(test1.style.top) - 51);
		}

		light1.style.height= (Math.max(0, (0 + inputval.value))) + 'px';
            });

	yslider2 = YAHOO.widget.Slider.getVertSlider("sliderbg2", "sliderthumb2", 0, 100);
	yslider2.setValue(77);
        yslider2.subscribe("change", function(offsetFromStart) {
		var test2 = get_item('sliderbg2');
                var test1 = get_item('sliderthumb2');
		var inputval = get_item('vertVal2');

		if(!test1.style.top) {
			//test1.style.top = startValue;
			inputval.value = startValue;
		}
		else {
			inputval.value = 100 - (parseInt(test1.style.top) - 51);
		}

		light2.style.height= (Math.max(0, (0 + inputval.value))) + 'px';
            });
}

function loaderinit() {
	// Initialize the temporary Panel to display while waiting for external content to load
	YAHOO.example.container.wait = new YAHOO.widget.Panel("wait",
		{ width:"240px",
		fixedcenter:true,
		close:false,
		draggable:false,
		modal:true,
		visible:false,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5}
		}
	);

	YAHOO.example.container.wait.setHeader("Loading, please wait...");
	YAHOO.example.container.wait.setBody("<img src=\""+ app_web_root+"style/loading.gif\"/>");
	YAHOO.example.container.wait.render(document.body);

	// Define the callback object for Connection Manager that will set the body of our content area when the content has loaded

	var content = document.getElementById("content");

	YAHOO.example.container.wait.show();
	// Connect to our data source and load the data
}


function loaderadds() {

	// Initialize the temporary Panel to display while waiting for external content to load
	NimblexAdds = new YAHOO.widget.Panel("adds", 
		{ width:"135px",
	/*	  height:"300px",*/
		xy: [0,(browsery-300)/2],
		close:true,
		draggable:true,
		modal:false,
		visible:false,
		zindex: 1,
		constraintoviewport:true,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:3}
		}
	);

	NimblexAdds.render(document.body);

	// Define the callback object for Connection Manager that will set the body of our content area when the content has loaded

	var content = document.getElementById("adds");
	content.style.display = '';

	NimblexAdds.show();

	// Connect to our data source and load the data
}


function loaderlegend() {

	// Initialize the temporary Panel to display while waiting for external content to load
	NimblexLegend = new YAHOO.widget.Panel("legend", 
		{ width:"100px",
	/*	  height:"300px",*/
		xy: [browserx-100,(browsery-300)/2],
		close:true,
		draggable:true,
		modal:false,
		visible:false,
		zindex: 1,
		constraintoviewport:true,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:3}
		}
	);

	NimblexLegend.render(document.body);

	// Define the callback object for Connection Manager that will set the body of our content area when the content has loaded

	var content = document.getElementById("legend");
	content.style.display = '';

	NimblexLegend.show();

	// Connect to our data source and load the data
}

function sizebarinit() {

	// Initialize the temporary Panel to display while waiting for external content to load
	sizebar_panel = new YAHOO.widget.Panel("size_bar_main", 
		{ width:"500px",
		xy: [(browserx-500)/2, 3],
		fixedcenter:false,
		close:false,
		draggable:false,
		modal:false,
		visible:false,
		zindex: 2,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:3}
		}
	);

	sizebar_panel.setBody('<div id="size_bar" class="size_bar">200 MB</div>');
	/*
	YAHOO.example.container.wait.setBody("<img src=\""+ app_web_root+"style/loading.gif\"/>");
	*/
	sizebar_panel.render(document.body);

	// Define the callback object for Connection Manager that will set the body of our content area when the content has loaded

	sizebar_panel.show();
	
	// Connect to our data source and load the data
}


function maininit() {
	getPanels();
	yuimainpanel = new YAHOO.widget.Panel("panel1",
		{width:"500px", 
		xy: [(browserx-500)/2, (browsery-400)/2],
		modal: false,
		close:false,
		fixedcenter:false,
		visible:false, 
		constraintoviewport:true,
		draggable:true,
		zindex: 10,
		effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:1} ,{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}]
		}
	);
	
	yuimainpanel.cfg.queueProperty('postmethod','form');
	yuimainpanel.render();

	var panel1 = get_item('panel1');
	panel1.style.display = "";
	sizebarinit();
}
function showsoundpanel(id) {
	var fullid = 'sound' + id;
	for(i=1; i<=3; i++) {
		if(i != id) {
			var div = get_item('sound' + i);
			div.style.display = 'none';
			var div = get_item('soundtab' + i);
			div.className = 'tab';
		}
	}
	var div = get_item(fullid);
	div.style.display = '';
	var div = get_item('soundtab' + id);
	div.className = 'selectedTab';
}

function changeCSS(id) {
	var style = get_item('style');
	if(id == 1) { style.href = app_web_root + 'style/skin1.css'; }
	if(id == 2) { style.href = app_web_root + 'style/skin2.css'; }
	if(id == 3) { style.href = app_web_root + 'style/skin3.css'; }
	if(id == 4) { style.href = app_web_root + 'style/skin4.css'; }
	if(id == 5) { style.href = app_web_root + 'style/skin5.css'; }
}

function playGreeting() {
	var handleSuccess = function(o){
		if(o.responseText !== undefined){
			playsound('soundPlayer', 'data/configured/boot_greeting/preview/', o.responseText);
			var player = get_item();
		}
	}

	var handleFailure = function(o){
		if(o.responseText !== undefined){
		}
	}

	var playText = get_item("customsound").value;
	var sUrl = app_web_root + "playgreeting/?text=" + playText;
 
	var callback =
		{
		  success:handleSuccess,
		  failure:handleFailure,
		  argument: { foo:"foo", bar:"bar" }
		};
	
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
  
}

function selectMe(id)
{
	var item = get_item('greeting_boot_' + id);
	item.checked = true;
}

function checkinput(el, id)
{
	var divIm = get_item(id);
	var ElVal = el.value;
	var regullar = /\W{1,50}/;
	if(regullar.exec(ElVal)) {
		divIm.innerHTML = "<img src='http://custom.nimblex.net/style/default/no.png'>";
	}
	else {
		divIm.innerHTML = "<img src='http://custom.nimblex.net/style/default/ok.png'>";
	}
}