
$(document).ready(function(){
	
	
	// Set logintexts
	removeusertextload();
	removepasstextload();
	
	
	// Set subsubmenu & subsubsubmenu
	$("a.subsubitem, a.subsubitemact").each(function(index) {
		if($(this).next(".subsubopen").length != 0){
			if($(this).hasClass("subsubitem")){
				$(this).removeClass("subsubitem");
				$(this).addClass("subsubitem2");
			}else if($(this).hasClass("subsubitemact")){
				$(this).removeClass("subsubitemact");
				$(this).addClass("subsubitemact2");
			}
		}
	});
	/*$(".subsubitemact").each(function(index) {
		if($(this).next(".subsubopen").length != 0){
			$(this).removeClass("subsubitemact");
			$(this).addClass("subsubitemact2");
		}
	});*/

	$(".subsubopen a:odd").addClass("odd")
	$(".subsubopen a:last-child").addClass("botrounded")
	//$(".subsubopen a").last().addClass("botrounded")
	//$(".subsubopen").children("a:last").addClass("botrounded");
	
		
	// Set click on outer elements & over for IE6
	$("div.prodbox1").click(function(){
		var link = $(this).find("a.outerlink").attr("href") || "";
		if(link!=""){document.location.href = link;}
	}); 
	
	
	// Set over for IE6 on product box
	if ($.browser.msie && (parseInt($.browser.version) == 6)){
		$("div.prodbox1").hover(
			function(){
				$(this).addClass("over");
			},
			function(){
				$(this).removeClass("over");
			}
		);
	}
	
	
	// Set active products onload
	$("div.productactive .prodbg").hide();
	$("div.productactive .prodbgactive").show();
	$("div.productactive + .productopen").show();
	
	
	// Product over & click
	
	/*$("img.prodbg").mouseenter(function(){
		$(this).hide();
		$(this).siblings("img.prodbgover").show();
	}).mouseleave(function(){
		$(this).show();
		$(this).siblings("img.prodbgover").hide();
	});*/
	
	$("div.product, div.productactive").mouseenter(function(){
		if($(this).hasClass('product')){
			$(".prodbgover", this).show();
			$(".prodbg, .prodbgactive, .prodbgactiveover", this).hide();
		}else if($(this).hasClass('productactive')){
			$(".prodbgactiveover", this).show();
			$(".prodbg, .prodbgover, .prodbgactive", this).hide();
		}
	});
	
	$("div.product, div.productactive").mouseleave(function(){
		if($(this).hasClass('product')){
			$(".prodbg", this).show();
			$(".prodbgover, .prodbgactive, .prodbgactiveover", this).hide();
		}else if($(this).hasClass('productactive')){
			$(".prodbgactive", this).show();
			$(".prodbg, .prodbgover, .prodbgactiveover", this).hide();
		}
	});
	
	$("div.product").live("click", function(){
		$(".prodbg", ".productactive").show();
		$(".prodbgover, .prodbgactive, .prodbgactiveover", ".productactive").hide();
		//$(".productactive + .productopen").hide();
		$(".productactive + .productopen").slideUp();
		$(".productactive").addClass("product").removeClass("productactive");
		$(".prodbgactive", this).show();
		$(".prodbg, .prodbgover, .prodbgactiveover", this).hide();
		$(this).addClass("productactive").removeClass("product");
		//$("+ div.productopen", this).show();
		$("+ div.productopen", this).slideDown();
	});
	
	$("div.productactive").live("click", function(){
		$(".prodbg", this).show();
		$(".prodbgover, .prodbgactive, .prodbgactiveover", this).hide();
		$(this).addClass("product").removeClass("productactive");
		//$("+ div.productopen", this).hide();
		$("+ div.productopen", this).slideUp();
	});
	
	
	// No default action on click
	$(".noclick").click(function(event){
		event.preventDefault();
  });
  
  
  // No bubbling
  $(".nobubble").click(function(event){
  	event.stopPropagation();
	});

	
});

//////////////////////////////////////////////////////////

var sts = new sack();
function chStatus(id,js,obj){
	var val = obj.options[obj.selectedIndex].value;
	sts.requestFile = '/inc/data.php?for=chstatus&id='+id+'&js='+js+'&val='+val;
	sts.runAJAX();	
}

var ajaxsc = new sack();
function getError(v){
	ajaxsc.requestFile = '/inc/data.php?for=err&v='+v;
	ajaxsc.onCompletion = showErr;
	ajaxsc.runAJAX();	
}

function showErr(){
	var t
	eval(ajaxsc.response);
	alert(t);
}

function chSmark(obj){
	if (obj.checked) { document.getElementById('smark').style.display = ''; }
	else { document.getElementById('smark').style.display = 'none'; }
}


////////////////////////////////////


var fullExpandTitle = '';
var restoreTitle = '';
var focusTitle = '';
var loadingText = '';
var loadingTitle = '';
var previousText = '';
var nextText = '';
var moveText = '';
var closeText = '';
var closeTitle = '';
var resizeTitle = '';

function re(p){
	document.location.href = p;	
}

function loadHs(ln) {
	var ajax = new sack();
	
	function getTxt(s, v, ln){
		ajax.requestFile = 'inc/data.php?for=ln&v='+v+'&l='+ln+'&str='+s;
		ajax.onCompletion = getIT;
		ajax.runAJAX();	
	}
	
	function getIT() {
		eval(ajax.response);
	}
	
	var t = 'fullExpandTitle:restoreTitle:focusTitle:loadingText:loadingTitle:previousText:nextText:moveText:closeText:closeTitle:resizeTitle';
	getTxt('hs',t, ln);
}

function clk(id, cat) {
	var ajax = new sack();
	ajax.requestFile = '/inc/setstat.php?'+cat+'='+id;
	ajax.runAJAX();	
}



//////////////////////////////////// Login texts

function setusertext(obj){
	if(!obj.value){
		show("loginemailname");
	}
}

function removeusertextload(){
	if(document.getElementById("loginemailfield") && document.getElementById("loginemailfield").value){
		hide("loginemailname");
	}
}

function setpasstext(obj){
	if(!obj.value){
		show("loginpassname");
	}
}

function removepasstextload(){
	if(document.getElementById("loginpassfield") && document.getElementById("loginpassfield").value){
		hide("loginpassname");
	}
}




//////////////////////////////////// Preload

if (document.images){
	preload_image_object = new Image();
	image_url = new Array();
	image_url.push(
		"/img/bgnd_product_over.gif",
		"/img/bgnd_product_active_over.gif",
		"/img/theme1/submen_visas_o.gif",
		"/img/theme1/submen_visas_ru_o.gif",
		"/img/theme1/submen_veikali_o.gif",
		"/img/theme1/submen_veikali_ru_o.gif",
		"/img/theme1/submen_iveikali_o.gif",
		"/img/theme1/submen_iveikali_ru_o.gif",
		"/img/theme1/submen_lveikali_o.gif",
		"/img/theme1/submen_lveikali_ru_o.gif",
		"/img/theme1/submen_jaunakas_o.gif",
		"/img/theme1/submen_jaunakas_ru_o.gif",
		"/img/theme1/submen_skatitakas_o.gif",
		"/img/theme1/submen_skatitakas_ru_o.gif",
		"/img/theme0/bgnd_subsubmid_over.gif",
		"/img/theme1/bgnd_subsubmid_over.gif",
		"/img/theme2/bgnd_subsubmid_over.gif",
		"/img/theme3/bgnd_subsubmid_over.gif",
		"/img/theme4/bgnd_subsubmid_over.gif",
		"/img/btn_close2_lv.gif"
	)
	var i = 0;
	for(i=0; i<=image_url.length; i++){
		preload_image_object.src = image_url[i];
	}
}



//////////////////////////////////// Add to favorites

function addfav(){
	if(document.all){window.external.AddFavorite('http://www.atlaides.lv','Atlaides.lv');}
	else if(window.sidebar){window.sidebar.addPanel('Atlaides.lv','http://www.atlaides.lv','');}
}



//////////////////////////////////// Set field text or empty or focus

function setfieldempty(obj,txt){
	if(obj.value == txt){
		obj.value = '';
	}
}

function setfieldtext(obj,txt){
	if(obj.value == ''){
		obj.value = txt;
	}
}

function setfocus(objid){document.getElementById(objid).focus();}



//////////////////////////////////// Show / Hide

function showhide(hidewhat){
	hideobject = document.getElementById(hidewhat);
	hideobject.style.display = hideobject.style.display=="none" ? "" : "none";
}

function show(showwhat){
	showobject = document.getElementById(showwhat);
	showobject.style.display = "";
}

function hide(hidewhat){
	hideobject = document.getElementById(hidewhat);
	hideobject.style.display = "none";
}



//////////////////////////////////// Change Style

function changeclass(obj, newclass){
	document.getElementById(obj).className = newclass;
}

//////////////////////////////////// Check Checkboxes

function checkall(group){
	for(i = 0; i < group.length; i++){
		group[i].checked = true;
	}
}

function uncheckall(group){
	for(i = 0; i < group.length; i++){
		group[i].checked = false;
	}
}

function select_all(name, value) {
	var forminputs = document.registerform.getElementsByTagName('input');
	for (i = 0; i < forminputs.length; i++) {
		var regex = new RegExp(name, "i");
		if (regex.test(forminputs[i].getAttribute('name'))) {
			if (value == '1') {
				forminputs[i].checked = true;
			} else {
				forminputs[i].checked = false;
			}
		}
	}
}

function checkuncheck(what){
	$checkuncheckobject = document.getElementById(what);
	$checkuncheckobject.checked = $checkuncheckobject.checked=="" ? "true" : "";
}



//////////// Product Active

/*function prodsetactivenoclick(what){
	prodid = what.getAttribute('id');
	prodbgnd = document.getElementById(prodid + 'bgnd');
	prodopen = document.getElementById(prodid + 'open');
	if(prodbgnd.getAttribute('src').match('_over')){
		prodbgndsrc = prodbgnd.getAttribute('src').split('_over.gif')[0] + '_active_over.gif';
	}else{
		prodbgndsrc = prodbgnd.getAttribute('src').split('.gif')[0] + '_active.gif';
	}
	prodbgnd.src = prodbgndsrc;
	prodopen.style.display = 'block';
}*/



//////////// Product Over

/*function productover(whichproduct){
	var prodid = whichproduct.getAttribute('id');
	var prodbgnd = document.getElementById(prodid + 'bgnd');
	var prodclass = whichproduct.getAttribute('class');
	if(!prodclass){
		prodclass = whichproduct.getAttribute('className'); //for IE
	}
	var prodsrc = prodbgnd.getAttribute('src').split('.gif')[0] + '_over.gif';
	prodbgnd.src = prodsrc;
	whichproduct.style.color = '#ffffff';
}

function productout(whichproduct){
	var prodid = whichproduct.getAttribute('id');
	var prodbgnd = document.getElementById(prodid + 'bgnd');
	var prodclass = whichproduct.getAttribute('class');
	if(!prodclass){
		prodclass = whichproduct.getAttribute('className');
	}
	var prodsrc = prodbgnd.getAttribute('src').split('_over.gif')[0] + '.gif';
	prodbgnd.src = prodsrc;
	if(prodclass == 'productactive'){
		whichproduct.style.color = '#000000';
	}else{
		whichproduct.style.color = '#555555';
	}
}*/



//////////// Product Click

/*function prodsetactive(what){
	prodid = what.getAttribute('id');
	prodbgnd = document.getElementById(prodid + 'bgnd');
	prodopen = document.getElementById(prodid + 'open');
	prodbgndsrc = prodbgnd.getAttribute('src').split('_over')[0] + '_active_over.gif';
	prodbgnd.src = prodbgndsrc;
	what.className = 'productactive';
	prodopen.style.display = 'block';
	what.style.color = '#ffffff';
}

function prodremoveactive(fromwhat){
	prodidactive = fromwhat.getAttribute('id');
	prodbgndactive = document.getElementById(prodidactive + 'bgnd');
	prodopenactive = document.getElementById(prodidactive + 'open');
	if(prodbgndactive.getAttribute('src').match('_over')){	//from self
		prodbgndsrcactive = prodbgndactive.getAttribute('src').split('_active_over.gif')[0] + '_over.gif';
		fromwhat.style.color = '#ffffff';
	}else{
		prodbgndsrcactive = prodbgndactive.getAttribute('src').split('_active')[0] + '.gif';
		fromwhat.style.color = '#555555';
	}
	prodbgndactive.src = prodbgndsrcactive;
	fromwhat.className = 'product';
	prodopenactive.style.display = 'none';
}

function productclick(whichproduct){
	var prodclass = whichproduct.getAttribute('class');
	if(!prodclass){prodclass = whichproduct.getAttribute('className');}	//for IE
	
	if(prodclass == 'product'){
		var activeEls = getElementsByClass('productactive',document.getElementById('contents'),'div');
		for(i=0; i<activeEls.length; i++){
			prodremoveactive(activeEls[i]);
		}
		prodsetactive(whichproduct);
	}
	
	if(prodclass == 'productactive'){
		prodremoveactive(whichproduct);
	}
}*/



//////////// Partners Prev / Next

var cols = new Array();
var actCol = 0;

function getCols(){
	cols = getElementsByClass('partcol',document.getElementById('leftcolumn'),'div');
}

function getActCol(){
	getCols();
	for(i=0; i<cols.length; i++){
		if(cols[i].style.display == ''){
			actCol = i + 1;
		}
	}
}

function partNext(){
	getActCol();
	document.getElementById('col' + actCol).style.display = "none";
	if(actCol == cols.length){
		document.getElementById('col1').style.display = "";
	}else{
		nextCol = actCol + 1;
		document.getElementById('col' + nextCol).style.display = "";
	}
}

function partPrev(){
	getActCol();
	document.getElementById('col' + actCol).style.display = "none";
	if(actCol == 1){
		document.getElementById('col' + cols.length).style.display = "";
	}else{
		prevCol = actCol - 1;
		document.getElementById('col' + prevCol).style.display = "";
	}
}



//////////////////////////////////// Get Elements by Class

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


