
function key(e) { 
  	e = (window.Event) ? e : event; 
if(e.keyCode==13) Search($('#q').val());
}

function readForm(form) {
    var data = '';
    $('input, textarea, select',form).each(function() {
         if(this.name!='') 
           if(this.type=='select-multiple') { 
             for(x=0;x<this.options.length;x++) {
                if(this.options[x].selected==true) data += '&'+this.name+'[]='+ encodeURIComponent(this.options[x].value);
             }
           } else if(this.type!='checkbox' && this.type!='radio') {
            value = this.value ? encodeURIComponent(this.value) : '';
            data +='&'+this.name+'='+value;
           } else if(this.checked==true) 
            data +='&'+this.name+'='+encodeURIComponent(this.value);  
    });

    return data;    
}


function sendInquiry(form) {

    f = $(form);
    var data = readForm(f);

    success = function(answ) {
            try {
                answ = eval("("+answ+")");
            } catch(ex) { answ = [answ]; }
            
            if(answ[0] == 1) {
                // f.html(answ[1]);
                alert(answ[1]);
            } else {
                alert(answ[0]);
            } 
        }
    
    $.post(f.attr('action'),data,success);
    
    return false;
}


 function uploadFormChanges(el) {
     el = $(el);
     var file = el.val();
     var fileName = el.prev();
      
     reWin = /.*\\(.*)/;
     var fileTitle = file.replace(reWin, "$1"); 
     reUnix = /.*\/(.*)/;
     fileTitle = fileTitle.replace(reUnix, "$1");
 
     fileName.html(fileTitle);
     el.parent().attr('title',fileTitle);
     
     var RegExExt =/.*\.(.*)/;
     var ext = fileTitle.replace(RegExExt, "$1").toLowerCase();
      
 }

 function slideSubPhoto() {
   var el,span,x,y,xC,yC,pos,start,side,interval,slide;
     
     el = $('#subPagePhoto'); 
     span = $('span',el);
     
     if(span.length<2) return;
    //$(el).unbind('mouseover').attr('onmouseover','');
    clearInterval(slideShow);
    
    for(i=0,l=span.length;i<l;i++) {
        if(span[i].className=='active') {
            break;
        }   
        
    }
    span.removeClass('active').css('z-index','50'); //.css('background-position','left -220px');
    $(span[i]).css('z-index','53');
 
    zi = i;
    for(z=0,l=span.length;z<l;z++) {
       zi++;
       if(zi>=span.length) zi = 0;
       $(span[zi]).css('z-index',50+z);
    }
    
    i++;
    if(i>=span.length) i = 0;

    el = $(span[i]);
    side = Math.round(Math.random()*10)%8;
    //console.log(side);
    /*switch(side) {
        case 0: start = '0px -220px'; y = -220; x = 0; yC = 3; xC = 0; break;
        case 1: start = '-400px 0px'; x = -400; y = 0; yC = 0; xC = 4; break;
        case 2: start = '-400px -220px'; x = -400; y = -220; yC = 2.2; xC = 4; break; 
        case 3: start = '400px 220px'; x = 400; y = 220; yC = -2.2; xC = -4; break; 
        case 4: start = '400px -220px'; y = -220; x = 400; yC = 2.2; xC = -4; break;    
        case 5: start = '-400px 220px'; y = 220; x = -400; yC = -2.2; xC = 4; break;
        case 6: start = '0px 220px'; y = 220; x = 0; yC = -3; xC = 0; break;
        case 7: start = '400px 0px'; y = 0; x = 400; yC = 0; xC = -4; break;
    }*/
    start = '-400px 0px'; x = -400; y = 0; yC = 0; xC = 5;
    el.addClass('active').css('z-index',50+span.length).css('background-position',start);
    
    /*for(i=-220;i<=50;i++) {
         el.css('background-position','left '+i+'px');
    }*/
    
    pos = -220; interval = null; 
    slide = function() {
        x+=xC; y+=yC;  
        if(xC>0 && x>0) x = 0; else if(xC<0 && x<0) x=0;
        if(yC>0 && y>0) y = 0; else if(yC<0 && y<0) y=0;
        
        pos = x+'px '+Math.round(y)+'px';
        el.css('background-position',pos);
       //console.log(pos);
        if( x==0 && y==0) {
            el.css('background-position','top left');
            clearInterval(interval);
            //el.parent().bind('mouseover',function() { slideSubPhoto(); });
        }   
    }
    slideShow = setInterval(slideSubPhoto,10000);
    
    interval = setInterval(slide,1);
    
    
 }
 var slideShow;
 $(document).ready(function() {
    // $('#subPagePhoto').bind('mouseover',function() { slideSubPhoto(this); }); 
     //slideShow = setInterval(slideSubPhoto,10000); 
     
 });
 
 function Search(q) {
	    var data = 'q='+q;

	    success = function(answ) {

	         if(answ==1) {
	               window.location.href=URL+'/Search';
	          } else alert(answ);
	      }
	
	  $.post(URL+'/Search',data,success);
	}
