var imgselected=new Array();

var headingDivHeight=0;

changeSubType = function(objectTypeId){
	var dstObj= $('#object_sub');
	dstObj.empty();
	dstObj.append('<option value="0">'+subObjectJSON[0]['value']+'</option>');
	try{
		for(i=0;i<subObjectJSON[objectTypeId].length;i++){
			dstObj.append('<option value="'+subObjectJSON[objectTypeId][i]['id']+'">'+subObjectJSON[objectTypeId][i]['value']+'</option>');
		}
	}catch(err){
		
	}
}

changeImage = function(imgName){
	if (navigator.appName.indexOf("Microsoft") != -1) {
	     var obj = window['imageviewer']
    }
    else {
        var obj = document['imageviewer']
    }
	obj.imageChangeWatcher(imgName);
	$('#selectedImg').val(imgName.substring(30, imgName.indexOf(".jpg")));
}

showBigPicture = function(imgName){
	//$('#imageviewer').css({visibility:'hidden'});
	tb_show('', document.location.protocol+'//'+document.location.host+'/'+document.location.pathname.substring(1,document.location.pathname.indexOf("index"))+imgName.substring(19, imgName.indexOf("&w")), "images");
	//alert('http://a3ia.com/anar/uusmaa/'+imgName.substring(19, imgName.indexOf("&w")));
	//alert(document.location.protocol+'//'+document.location.host+'/'+document.location.pathname.substring(1,document.location.pathname.indexOf("index")));
}

mapCountyOver = function(countyID,destObj){
	if (navigator.appName.indexOf("Microsoft") != -1) {
	     var obj = window['mapava']
    }
    else {
        var obj = document['mapava']
    }
    
	obj.countyOverActive(countyID);
	
}	

flashResize = function(flashHeight){
	$('#imageviewer').attr('height',flashHeight);	

}

printObject = function(objectId){
 	var objects = imgselected;
 	var imglist = '';
 	for(i=0;i<objects.length;i++){
 		
			imglist+=objects[i]+',';
	}
	imglist=imglist.substr(0,(imglist.length-1));
	$('#pdf_print').html('<img src="webadmin/gfx/loader_min.gif"> Objektist genereeritakse PDF-i, palun oota...').show();
	$.getJSON('index.php',{'page':'objects','action':'generatepdf','output':'none','id':objectId,'ids':imglist,'pdf_layout': $('#pdf_layout').val()},function(data){
		$('#pdf_print').html('Objektist on valmis PDF: <br /><div style="padding: 15px 0 10px 0;margin: 0 auto 0 auto;width: 250px;"><div style="float:left;"><a href="index.php?page=objects&action=downloadpdf&mehtod=d&output=none&file='+data.filename+'&name='+data.name+'" class="pdf_file">Lae alla</a></div><div style="float:left;padding-left:20px;"><a href="index.php?page=objects&action=downloadpdf&mehtod=o&output=none&file='+data.filename+'&name='+data.name+'" target="_blank" class="pdf_file">Ava uues aknas</a></div><div class="clear"></div></div>');	
	});
 }
 
printImageArray = function(imgId){
	var tmparray = new Array();
	var keyRemove = false;
		
	for(i=0;i<imgselected.length;i++){

		if(imgselected[i]!=imgId){
			tmparray.push(imgselected[i]);
		}else{
			keyRemove=true;
		}
	}
	imgselected=tmparray;
	if(keyRemove==false&&imgselected.length<4)imgselected.push(imgId);
	
	//alert(imgselected.length+'|'+keyRemove);
	if(imgselected.length>3)$('INPUT[type="checkbox"]').not(':checked').attr('disabled','disabled');
	else if(imgselected.length==3&&keyRemove==true)$('INPUT[type="checkbox"]:disabled').removeAttr('disabled');
	
}
 
 
printImageToggle = function(inputKey){
	var destElement=$('INPUT[type="checkbox"]:eq('+inputKey+')')
	if(destElement.attr('disabled')==false)destElement.attr('checked',(destElement.attr('checked')==true?false:true));	
}

showMap = function(activeItem){
	if(activeItem==true){
		$('#object_media').hide();
		$('#object_thumbs').hide();
		$('#show_map').show();
	}else{
		$('#object_media').show();
		$('#object_thumbs').show();
		$('#show_map').hide();
	}
}




$(document).ready(function(){
	$('div').ifixpng();
	headingDivHeight=($('#header_text').height()/2)-$('.infoHeading').height();
	$('.infoHeading').css({marginTop: headingDivHeight+'px'});
	
	headingDivHeight=($('#header_text').height()/2)-($('.show_address').height()>25?18:$('.show_address').height());
	$('.show_address').css({marginTop: headingDivHeight+'px'});
})