
jQuery.noConflict();

//
// tjpzoom 2005.11.29 - 2005.12.02.
// details/usage: http://valid.tjp.hu/zoom/
//

var zoomw=120;
var zoomh=120;
var defzoomamount=2;

var zoomamountstep=1.2;
var zoomsizemin=1000;
var zoomsizemax=100000;
var zoomsizestep=1.2;
var zoomamountmin=1;
var zoomamountmax=12;

function zoom_set(evt) {
 var evt = evt?evt:window.event?window.event:null; if(!evt){ return;}
 if(zoomid=='' || parseInt(document.getElementById(zoomid+'_container').style.width) == 0) {return true;}
 if(evt.keyCode==37 || evt.keyCode==100) {zoomw/=zoomsizestep; zoomh/=zoomsizestep; if(zoomw*zoomh<zoomsizemin) {zoomh=Math.sqrt(zoomsizemin/zoomratio); zoomw=zoomh*zoomratio;} zoom_init(); zoom_move(); return;} //left
 if(evt.keyCode==39 || evt.keyCode==102) {
  zoomw*=zoomsizestep; zoomh*=zoomsizestep;
  if(zoomw*zoomh>zoomsizemax) {zoomh=Math.sqrt(zoomsizemax/zoomratio); zoomw=zoomh*zoomratio;}
  if(zoomw>objw) {zoomw=objw; zoomh=objw/zoomratio;}
  else if(zoomh>objh) {zoomh=objh; zoomw=objh*zoomratio}
  zoom_init(); zoom_move(); return;
 } //right
 if(evt.keyCode==40 || evt.keyCode==98)  {zoomamount/=zoomamountstep; if(zoomamount<zoomamountmin) {zoomamount=zoomamountmin;} zoom_init(); zoom_move(); return;} //down
 if(evt.keyCode==38 || evt.keyCode==104) {zoomamount*=zoomamountstep; if(zoomamount>zoomamountmax) {zoomamount=zoomamountmax;} zoom_init(); zoom_move(); return;} //up
 return;
}

function zoom_init() {
 document.getElementById(zoomid+'_clip').style.width=objw*zoomamount+'px';
 document.getElementById(zoomid+'_clip').style.height=objh*zoomamount+'px';
 setTimeout("document.getElementById('"+zoomid+"_trigger').focus();",0);
}

function zoom_move(evt) {
 if(typeof(evt) == 'object') {
  var evt = evt?evt:window.event?window.event:null; if(!evt){ return;}
  if(evt.pageX) {
   xx=evt.pageX - ffox;
   yy=evt.pageY - ffoy;
  } else {
   if(typeof(document.getElementById(zoomid)+1) == 'number') {return true;} //mert az ie egy ocska kurva
//   xx=evt.x - ieox;
//   yy=evt.y - ieoy;
   xx=evt.clientX - ieox;
   yy=evt.clientY - ieoy;
  }
 } else {
  xx=lastxx; yy=lastyy;
 }
 lastxx=xx; lastyy=yy;
 document.getElementById(zoomid+'_clip').style.margin=((yy-zoomh/2 > 0)?(zoomh/2-yy*zoomamount):(yy*(1-zoomamount)))+'px 0px 0px '+((xx-zoomw/2 > 0)?(zoomw/2-xx*zoomamount):(xx*(1-zoomamount)))+'px';
 document.getElementById(zoomid+'_container').style.margin=((yy-zoomh/2 > 0)?(yy-zoomh/2):(0))+'px 0px 0px '+((xx-zoomw/2 > 0)?(xx-zoomw/2):(0))+'px';

 w2=((xx+zoomw/2<objw)?((zoomw/2<xx)?(zoomw):(zoomw/2+xx)):(zoomw/2+objw-xx)); if(w2<0) {w2=0;} document.getElementById(zoomid+'_container').style.width=w2+'px';
 h2=((yy+zoomh/2<objh)?((zoomh/2<yy)?(zoomh):(zoomh/2+yy)):(zoomh/2+objh-yy)); if(h2<0) {h2=0;} document.getElementById(zoomid+'_container').style.height=h2+'px';
 return false;
}

function zoom_off() {
 if(zoomid != '') {
  document.getElementById(zoomid+'_container').style.width='0px';
  document.getElementById(zoomid+'_container').style.height='0px';
 }
 zoomid='';
}

function countoffset() {
 ieox=0;ieoy=0;
 for(zmi=0;zmi<50;zmi++) {
  zme='document.getElementById(zoomid)';
  for(zmj=1;zmj<=zmi;zmj++) {
   zme+='.offsetParent';
  }
  if(eval(zme)+1 == 1) {zmi=100} else {ieox+=eval(zme+'.offsetLeft'); ieoy+=eval(zme+'.offsetTop');}
 }
 ffox=ieox;
 ffoy=ieoy;
 if(document.documentElement && document.documentElement.scrollTop) {
  ieox-=document.documentElement.scrollLeft;
  ieoy-=document.documentElement.scrollTop;
 } else {
  ieox-=document.body.scrollLeft;
  ieoy-=document.body.scrollTop;
 }
}

function zoom_on(evt,ow,oh,lowres,highres) {
 thisid=lowres+highres+ow+oh;
 thisid='zoom_'+thisid.replace(/[^a-z0-9]/ig,'')
 if(zoomid==thisid) {return;}
 if(typeof(highres) == typeof(nemistudom)) {highres=lowres;}
 var evt = evt?evt:window.event?window.event:null; if(!evt){ return;}
 zoomamount=defzoomamount;
 objw=ow;
 objh=oh;
 zoomid=thisid;
 if(evt.pageX) {
  evt.target.parentNode.id=thisid;
  countoffset();
  lastxx=evt.pageX - ffox; //mert a ff egy ocska kurva
  lastyy=evt.pageY - ffoy;
 } else {
  evt.srcElement.parentNode.id=thisid;
  countoffset();
//  lastxx=evt.x - ieox; //mert az ie egy ocska kurva
//  lastyy=evt.y - ieoy;
  lastxx=evt.clientX - ieox;
  lastyy=evt.clientY - ieoy; 
 }
 document.getElementById(thisid).style.width=ow+'px';
 document.getElementById(thisid).style.height=oh+'px';
 document.getElementById(thisid).style.overflow='hidden';
 document.getElementById(thisid).innerHTML='<div style="position:absolute; overflow:hidden; width:0; height:0;" id="'+thisid+'_container" onmousemove="zoom_move(event);" onmouseout="zoom_off()"><img src="'+highres+'" alt="" id="'+thisid+'_clip" style="padding:0;margin:0;border:0;" /></div><img src="'+lowres+'" id="'+thisid+'_pic" alt="" style="padding:0;margin:0;border:0;width:'+ow+'px; height: '+oh+'px"/><input type="text" id="'+thisid+'_trigger"  style="width:0;height:0;border:0;margin:0; padding:0;overflow:hidden;"/>';
 if(zoomw>objw) {zoomw=objw; zoomh=objw/zoomratio;}
 else if(zoomh>objh) {zoomh=objh; zoomw=objh*zoomratio}
 zoom_init();
 zoom_move('');
 if(document.all) {
  document.onkeydown=zoom_set;
 } else {
  window.captureEvents(Event.KEYDOWN);
  window.onkeydown = zoom_set;
 }
 return false;
}

var zoomamount=defzoomamount; var objw;var objh;var zoomid=''; var zoomratio=zoomw/zoomh; var ieox=0; var ieoy=0; var ffox=0; var ffoy=0;


var MainUrl = "http://new.lm.gov.lv/";

//var RealCss = 0;
var RealCssFile = '/templates/css/6a992d5529f459a44fee58c733255e86.css';//jQuery("link").attr('href');
var SHOW = getCookie("SHOW");
var CSSFILE = getCookie("CSS_FILE");

//register(RealCssFile,'CSS_FILE');
//alert(SHOW);
//alert(CSSFILE);
if(getCookie("CSS_FILE") == 'undefined'){
	register(RealCssFile,'CSS_FILE');
	register('normal','SHOW');
}


function initdata(){
	var h = jQuery(document).height();
	var rh  = h-130;
	var rhContenth  = rh - 254;
	jQuery("#wrap-left-border p img").height(h);
	jQuery("#wrap-right-border p img").height(h);
	jQuery("#wrap").height(h);
	jQuery("#right").height(rh);
	jQuery("#contentLeft").height(rhContenth);
	

}

function inititemsdata(){
	var h = jQuery(document).height();
	var rh  = h-130;
	jQuery("#wrap-left-border p img").height(h);
	jQuery("#wrap-right-border p img").height(h);
	jQuery("#wrap").height(h);
	jQuery("#right").height(rh);
	

}


function LoadImage(imageID){


	
	jQuery("#contentImg div").hide();
	jQuery("#image"+imageID).show();
	jQuery("#image"+imageID+" div").show();
	jQuery("#pic-navig li a").removeClass();
	jQuery("#pic-navig li a#picMenuItem"+imageID).addClass("selected");
}

function makeLarger(){	
	if(SHOW == 'redze'){
		jQuery("link").attr('href',CSSFILE);
		register('normal','SHOW');
		document.location.href='/';
	} else {
		jQuery("link").attr('href','/redze.css');
		register('redze','SHOW');
		document.location.href='/';
	}
}

if(SHOW == 'redze')
	jQuery("link").attr('href','/redze.css');
else
	jQuery("link").attr('href',CSSFILE);

    
    
function openWorker(id){
    jQuery("#workers-list a").removeClass('workerOpen');
    jQuery("#worker-"+id+" a").addClass('workerOpen');
    jQuery("#worker-data-"+id).slideDown();
}
var mainMaenuOpend = 0;
function OpenMainMenu(id){
    if(mainMaenuOpend == id){
        jQuery("#Mneu"+id+" ul").slideUp();
        mainMaenuOpend = 0;
    } else {
        if(mainMaenuOpend == 0){
            jQuery("#Mneu"+id+" ul").slideDown();
            mainMaenuOpend = id;
        } else{
            jQuery("#Mneu"+mainMaenuOpend+" ul").slideUp();
            jQuery("#Mneu"+id+" ul").slideDown();
            mainMaenuOpend = id;
        }
    }
}
function LoadCalendarMonth(Month){
    var Year = jQuery("#CalendarYear").val();
    var data = jQuery.ajax({type: "POST",async: false,url: MainUrl+"ajax.php",data: 'type=calendar&Y='+Year+'&m='+Month}).responseText;
    jQuery("#calendar").html(data);
    //alert(responseText);
    //var resp = split();
}
function removeFromBasket(ItemID){
	var data = jQuery.ajax({type: "POST",async: false,url: "/ajax.php",data: 'type=basket&action=add&id='+ItemID}).responseText;
	jQuery("#item-"+ItemID).slideUp('fast');
	var price = jQuery("#itemPrice-"+ItemID).val();
	var total = jQuery("#totalInput").val();
	var newTotal = Number(total-price);
	var newVAT = Number(newTotal*0.18);
	var newTotalTotal = Number(newTotal+newVAT);
	
	
	jQuery("#totalInput").val(newTotalTotal);
	jQuery("#totalSimple").html(newTotal);
	jQuery("#totalVat").html(newVAT);
	jQuery("#totalTotal").html(newTotalTotal);
	
}
function AddTuBasket(ItemID){
    var data = jQuery.ajax({type: "POST",async: false,url: "/ajax.php",data: 'type=basket&action=add&id='+ItemID}).responseText;
    var data2 = jQuery.ajax({type: "POST",async: false,url: "/ajax.php",data: 'type=basket&action=chek'}).responseText;
    if(data2 == 'show')
    	jQuery(".chekout").show();
    else
    	jQuery(".chekout").hide();
    	
    jQuery("#basketLink"+ItemID).html(data);
}
function LoadCalendarYear(Year){
    var Month = jQuery("#CalendarMonth").val();
    var data = jQuery.ajax({type: "POST",async: false,url: MainUrl+"ajax.php",data: 'type=calendar&Y='+Year+'&m='+Month}).responseText;
    jQuery("#calendar").html(data);
    //alert(responseText);
    //var resp = split();
}
function setVote(id){
    jQuery("#vote").val(id);
}
function SubmitVote(){
    var vote = jQuery("#vote").val();
    var pool = jQuery("#poolvalue").val();
    if(vote.length > 0 ){
        var data = jQuery.ajax({type: "POST",async: false,url: MainUrl+"ajax.php",data: 'type=pool&id='+pool+'&vote='+vote}).responseText;    
        if(data.length){
            GetVoteResaults();
        }
    } 
}
function GetVoteResaults(){
    var pool = jQuery("#poolvalue").val();
    var data = jQuery.ajax({type: "POST",async: false,url: MainUrl+"ajax.php",data: 'type=getPoolReasaults&id='+pool}).responseText;  
    jQuery("#pool-box").html(data);
}
function sumbmitSerch(){
	var srcString = jQuery("#srcString").val();
	document.location.href='/serach/?search='+srcString;
}

function setCookie(name, value, expire) {
          document.cookie = name + "=" + escape(value)
          + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
function register(name,cokiea) { 
          var today = new Date()
          var expires = new Date()
          expires.setTime(today.getTime() + 60*60*24*365)
          setCookie(cokiea, name, expires)
}
function getCookie(Name) {
          var search = Name + "="
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(search) 
                    if (offset != -1) { // if cookie exists 
                              offset += search.length 
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset) 
                              // set index of end of cookie value
                              if (end == -1) 
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    } 
          }
}

//jQuery(document).ready(initdata);

