window.addEvent('domready', function(){
    init();
});

function init() {
    contactForm();
    changeImg();
    getPhoneIMG();
    setStartImg();

}

function changeImg() {
    var itarr = new Array();
    itarr = $$('div[class=example]');
    itarr.each(function(it){
	    it.addEvent('click',function(e){
		    var child = it.getChildren()[0].getChildren();
		    //$('center_phone').innerHTML = '';
		    var phone_selected = $('phone_selected').getProperty('value');
//$('site_selected').setProperty('value','2');
		    $('center_phone').set('html','<img src="'+it.getChildren()[phone_selected].value+'" alt="" width="200px"  />');
		    itarr.each(function(i){
			    i.getChildren()[0].getChildren()[0].setProperty('class','example-title title-usual');
			    if (i.getCoordinates()['width'] != it.getCoordinates()['width']) {
			    	i.setStyle('width', '270px');
		    	}
		    });
		    child[0].setProperty('class','example-title');
		    if (this.getCoordinates()['width']<=272) {
				var fx2wn = new Fx.Morph(it, {duration: 200, wait: true});
				fx2wn.start({'width': [270, 318]});
		    }
	    });
    });
}

function setStartImg() {
    var phone_selected = $('phone_selected').getProperty('value');
    var itarr = $$('div[class=example]');
    var it = itarr.shift();
    $('center_phone').set('html','<img src="'+it.getChildren()[phone_selected].value+'" alt="" width="200px"/>');
    it.setStyle('width', '318px');
    var sp1 = $('smallphone1');
    var dvi = sp1.getChildren();
    dvi[2].setStyle('background','url(../images/lights/l1.png) no-repeat center');
    dvi[3].setStyle('color','#fff');
}


/* one777 10.08.2010
function Asend(cur_img, pic) {

    var way = document.URL.split("?");
        
        var r = new Request({
            url: way[0],
            method: 'get',
      //      data: "ACTION=ajax"+"&event="+com+"&id="+id,
            data: "REQ=ru/services/",
            
            onRequest: function() {
                                        
            },
            onComplete: function() {
                var msg = this.response.text;
      //          $('portfolio_div_title1').innerHTML = '<img src='+ cur_img +'>';
      //          alert(msg);
            }
        }).send();
        
    return true;
}



$('portfolio_div_title1').addEvent('click', function(){
    var cur_img = $('portfolio_img1').value;
    if (cur_img != '') {
        Asend(cur_img, 1);
    }
});
    
$('portfolio_div_title2').addEvent('click', function(){
    var cur_img = $('portfolio_img2').value;
    if (cur_img != '') {
        Asend(cur_img, 2);
    }
});

$('portfolio_div_title3').addEvent('click', function(){
    var cur_img = $('portfolio_img3').value;
    var response = '';
    if (cur_img != '') {
        Asend(cur_img, 3);
    }
});

*/

/*
function centerdiv(id){
  var ww = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
  var hh = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
  var tt = window.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
  var h = $(id).getChildren('img')[0].height;
  var t = Math.max(70,$(id).getChildren('img')[0].width);
  $(id).setStyle('width',t+4);
  var nw = (ww.toInt()-t.toInt())/2;
  var nh = tt + (hh-h)/2;
  if (nh < 0) {nh = 0;}
  $(id).setStyle('left', nw);
  $(id).setStyle('top', nh);
  $(id).setStyle('display', 'block');
}

var ovl = new Element('div', {id:'overlay'});
ovl.setStyle('opacity',0.0);
ovl.injectTop($(document.body));

$$('a[class=make_me_bigger]').each(function(it){
    
    it.addEvent('click',function(e){
        var lnk = it.getProperty('href');
        e = new Event(e).stop();
                     
        var fx = new Fx.Morph($('overlay'), {duration: 200, wait: false});
                fx.start({
                  'opacity': [0, 0.8]
        }).chain(function(){
        
        var pic = new Element('div',{
                'id':'big-foto-picture',
                'class':'big-foto-gal',
                'styles':{
                    'display':'none'
                    }
        });
        
        pic.addEvent('click',function(e){
                e = new Event(e).stop();
                    this.dispose();
                    var fx = new Fx.Morph($('overlay'), {duration: 200, wait: false});
                    fx.start({
                      'opacity': [0.8, 0.0]});
            
        });
        
        var closeelement = new Element('div',{
                id : 'closepic',
                'class':'close-button',
                'html':'<a href="#">'+$('GCLOSE').value+'</a>'
            });
        
        closeelement.addEvent('click',function(e){
                e = new Event(e).stop();
                    if ($('big-foto-picture')) {$('big-foto-picture').dispose();}
                    var fx1 = new Fx.Morph($('overlay'), {duration: 200, wait: false});
                    fx1.start({
                      'opacity': [0.8, 0.0]});    
        });
        closeelement.addEvent('mouseover',function(e){
                this.setStyle('display','block');
            });
        
            closeelement.injectInside(pic);
            
            pic.injectInside($(document.body));            
        
        var img = new Asset.image(lnk, {
                    id: 'picline', 
                    alt: 'bigpic',
                    onload: onloaded
        });
        
        function onloaded() {
            centerdiv('big-foto-picture');
        }
        
        img.injectInside($('big-foto-picture'));

            $('picline').addEvent('mouseover',function(e){
                $('closepic').setStyle('display','block');
            });
            $('picline').addEvent('mouseout',function(e){
                $('closepic').setStyle('display','none');
            });    
        
        });
                    
        $('overlay').addEvent('click',function(e){
                e = new Event(e).stop();
                    if ($('big-foto-picture')) {$('big-foto-picture').dispose();}
                    var fx = new Fx.Morph($('overlay'), {duration: 200, wait: false});
                    fx.start({
                      'opacity': [0.8, 0.0]});
            
        });
            
    });
                              
});


*/




    

