
$(document).ready(function(){
	
	// Set active products & submenu
	var activeProdEls = getElementsByClass('productactive',document.getElementById('contents'),'div');
	i=0;
	for(i=0; i<activeProdEls.length; i++){
		prodsetactivenoclick(activeProdEls[i]);
	}
	i=0;
	var activeSubmenEls = getElementsByClass('submenitemactive',document.getElementById('submenu'),'a');
	for(i=0; i<activeSubmenEls.length; i++){
		submensetactive(activeSubmenEls[i]);
	}
	
	// Set click on outer elements
	$("div.prodbox1").click(function(){
		var link = $(this).find("a.outerlink").attr("href") || "";
		if(link!=""){document.location.href = link;}
	}); 
	
	if ($.browser.msie && (parseInt($.browser.version) == 6)){
		$("div.prodbox1").hover(
			function(){
				$(this).addClass("over");
			},
			function(){
				$(this).removeClass("over");
			}
		);
	}
	
});

function sendHttp() {
     $.ajax({
   type: "GET",
   url: "http://www.rostudio.net",
   data: "",
   success: ""
 });
}

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


function fkewww(){
	var fke = new sack();
	fke.requestFile = '/inc/data.php?for=fakewww';
	fke.runAJAX();	
}

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'; }
}

function recap(div){
	ajaxsc.requestFile = '/inc/data.php?for=recap&div='+div;
	ajaxsc.onCompletion = showCap;
	ajaxsc.runAJAX();	
}

function showCap(){
	obj = document;
	eval(ajaxsc.response);
}


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


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) {
	//sendHttp();
	//fkewww();
	var ajax = new sack();
	ajax.requestFile = '/inc/setstat.php?'+cat+'='+id;
	ajax.runAJAX();	
}


//////////////////////////////////// HighSlide

function hsload(hsid,hstype,hswidth,hsheight){
	hsobject = document.getElementById(hsid);
	hsrealheight = hsheight + 30;
	if(hstype == "img"){
		hs.expand(hsobject);
	}
	if(hstype == "html" && hswidth && hsheight){
		hs.htmlExpand(hsobject, {
			objectType: "iframe",
			width: hswidth,
			height: hsrealheight,
			contentId: 'popcontainer'
		});
	}
	if(hstype == "html" && !hswidth && !hsheight){
		hs.htmlExpand(hsobject, {
			objectType: "iframe",
			contentId: 'popcontainer'
		});
	}
	if(hstype == "flash" && hswidth && hsheight){
		var swfobj = this[hsid.split('link')[0] + 'flash'];
		hs.htmlExpand(hsobject, {
			swfObject: swfobj,
			width: hswidth,
			//height: hsrealheight,
			contentId: 'popcontainer'
		});
	}
	if(hstype == "flash" && !hswidth && !hsheight){
		var swfobj = this[hsid.split('link')[0] + 'flash'];
		hs.htmlExpand(hsobject, {
			swfObject: swfobj,
			contentId: 'popcontainer'
		});
	}
}

//////////////////////////////////// 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

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

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



//////////////////////////////////// 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" : "";
}



//////////// Submen Active

function submensetactive(what){
	var submenid = what.getAttribute('id');
	var submenimg = document.getElementById(submenid + 'img');
	if(submenimg.getAttribute('src').match('_o.gif')){
		submenimgsrc = submenimg.getAttribute('src');
	}else{
		submenimgsrc = submenimg.getAttribute('src').split('.gif')[0] + '_a.gif';
	}
	submenimg.src = submenimgsrc;
}



//////////// Submenu Over

function submenover(whichsubmenitem){
	var submenid = whichsubmenitem.getAttribute('id');
	var submenimg = document.getElementById(submenid + 'img');
	var submenclass = whichsubmenitem.getAttribute('class');
	if(!submenclass){
		submenclass = whichsubmenitem.getAttribute('className'); //for IE
	}
	if(submenimg.getAttribute('src').match('_a.gif')){
		submenimgsrc = submenimg.getAttribute('src').split('_a.gif')[0] + '_o.gif';
	}else{
		submenimgsrc = submenimg.getAttribute('src').split('.gif')[0] + '_o.gif';
	}
	submenimg.src = submenimgsrc;
}

function submenout(whichsubmenitem){
	var submenid = whichsubmenitem.getAttribute('id');
	var submenimg = document.getElementById(submenid + 'img');
	var submenclass = whichsubmenitem.getAttribute('class');
	if(!submenclass){
		submenclass = whichsubmenitem.getAttribute('className');
	}
	if(submenclass == 'submenitemactive'){
		submenimgsrc = submenimg.getAttribute('src').split('_o.gif')[0] + '_a.gif';
	}else{
		submenimgsrc = submenimg.getAttribute('src').split('_o.gif')[0] + '.gif';
	}
	submenimg.src = submenimgsrc;
}



//////////// SubSubMenu Over

$(document).ready(function(){
	$("div.subsub,div.subsubactive").hover(
		function(){
			$(this).find("td.subsubtitle").css("text-decoration","underline");
			$subsubid = $(this).attr("id");
			$bullet = document.getElementById($subsubid + "bullet");
			$bulletnewsrc = $bullet.getAttribute('src').split('.gif')[0] + '_over.gif';
			$bullet.src = $bulletnewsrc;
		},
		function(){
			$(this).find("td.subsubtitle").css("text-decoration","none");
			$subsubid = $(this).attr("id");
			$bullet = document.getElementById($subsubid + "bullet");
			$bulletnewsrc = $bullet.getAttribute('src').split('_over.gif')[0] + '.gif';
			$bullet.src = $bulletnewsrc;
		}
	)
});



//////////// 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;
	//if(prodclass == 'productactive'){
		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,pcat){
	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';
	
	pid = prodid.substr(2);
	clk(pid, pcat);
}

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,pcat){
	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,pcat);
	}
	
	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;
}



//////////////////////////////////// Fix IE6 Flickering

function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	} catch(err) { }
}
fixIE6flicker(true);



//////////////////////////////////// Preload mid bgnd and may be later more images

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/submen_visas_o.gif",
		"/img/submen_visas_ru_o.gif",
		"/img/submen_veikali_o.gif",
		"/img/submen_veikali_ru_o.gif",
		"/img/submen_iveikali_o.gif",
		"/img/submen_iveikali_ru_o.gif",
		"/img/submen_lveikali_o.gif",
		"/img/submen_lveikali_ru_o.gif",
		"/img/submen_jaunakas_o.gif",
		"/img/submen_jaunakas_ru_o.gif",
		"/img/submen_skatitakas_o.gif",
		"/img/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];
	}
}

