
var bigSite={
	//DINAMIC PARAMS
	ref_per_row:0,
	ref_act_dim:0,
	descr_pager:0,
	menu_height:0,
	descr_max_pic:0,
	tmp:{},	
	//FIX PARAMS
	cls:'big',
	txt:{'hu':{'news':'hír'},'uk':{'news':'news'}},
	ga_lnk:{
		hu:{
			lng:'hu',
			contacts:'kapcsolat',
			about_us:'rolunk',
			solutions:'megoldasaink'
		},
		uk:{
			lng:'en',
			contacts:'contacts',
			about_us:'about_us',
			solutions:'solutions'
		}
	},
	ref_min_width:195,	//the best fit to 240px, val:195
	min_ref_per_row:3,
	ref_count:0,
	descr_pos:{3:1,4:5},
	descr_pos_corr:10,
	//FLAGS
	isResize:false,
	isOriented:false,
	isAfterIntro:false,

	init:function(){
		this.ref_count=$('div.ref').not('.menu_box').length;
		this.commonInit();
		this.isAfterIntro=true;
		this.start_intro();
		$(window).scroll(function(){
			if($('div#descr_l:not(:hidden)').length>0) {$('div.exit_descr_l').click();}
		});
		//MENU CONTENT CLICK
		$('li.main_menu').bind('click',$.proxy(function(event){
			var height=25;
			$('div.refLayer').fadeOut(400,function(){$(this).remove();});
			var $target=$(event.currentTarget);
			if($target.children('p#port_menu').length>0) {
				var $el=$target.children('p#port_menu');
			} else {
				var $el=$target;
			}
			var id=$target.attr('id');
			if(id!="main_logo") {
				if(id!="main_portfolio"){
					$('html,body').css({overflow:'auto'});
					var param={
						cls:'menuLayer',
						top:0,
						left:this.ref_act_dim,
						dWidth:$(window).width()-this.ref_act_dim-3,
						dHeight:this.menu_height,
						dLeft:this.ref_act_dim+3,
						dTop:0
					};
					if($('p.#port_menu').attr('class')=='selected'){$('li#main_portfolio').animate({height:height}, 'slow');}
					$('html').animate({scrollTop:0},500,$.proxy(function(){
						this.getAjax(id,id,param);
					},this));
				} else {
					this.close_intro();
					$('li#main_portfolio').animate({height:height+$('ul#sub_menu').height()+7}, 'slow');
					if($('div#descr_l').length >0) {$('div#descr_l').fadeOut('slow',function(){$(this).remove()});}
//					this.track_GA('/'+this.ga_lnk[lang]['lng']+'/portfolio/');
				}
				$('li.main_menu,p#port_menu').removeClass('selected');
				$el.addClass('selected');
			}
		},this));

		$('li.sub_menu').bind('click',$.proxy(function(e){
			$('html').animate({scrollTop:0},500,$.proxy(function(){
				this.filterRef($(e.currentTarget).attr('id'));
			},this));
			$('li.sub_menu').removeClass('selected');
			$(e.currentTarget).addClass('selected');
		},this));

		if(document.location.hash!="" && $('li'+document.location.hash).length>0){
			$('li'+document.location.hash).click();
		}
	},
	
	start_intro:function(){
		var wait_delay=5000;
		var animate_delay=1000;
		var act_layer=1;
		var delay_between_anim=6500;
		var $intro_layer=$('div#intro_layer');
		var max_layer_count=$intro_layer.children('div').length;
		if($intro_layer.hasClass('unset')){
			$intro_layer.css({width:$(window).width()-this.ref_act_dim-4,left:this.ref_act_dim+2});
			this.resizeIntroIE(true);
			$intro_layer.removeClass('unset');
		}
		$.waitForImages = {hasImageProperties: []};
		$intro_layer.waitForImages($.proxy(function(){
			this.resizeIntroIE(false);
			if(!$intro_layer.hasClass("intro_bg")){$intro_layer.addClass("intro_bg");}
			$intro_layer.css({width:$(window).width()-this.ref_act_dim-4,left:this.ref_act_dim+2});
			for(var j=0;j<(max_layer_count/3);j++){
				for(var i=0;i<3;i++){
					$('div.layer_'+act_layer).delay(animate_delay+(100*(i-1))+(j*delay_between_anim)).animate({'left':'50%'},{
						"duration": animate_delay+(100*(i-1)),
						"easing":"easeOutBack",
						"complete":function(){
							$(this)
							.delay(wait_delay-(300*(i-1)))
							.animate({'left':'-200%'},{
								"duration": animate_delay-(100*(i-1)),
								"easing":"easeInBack",
								"complete":function(){
									$(this).css({left:'200%'});
									if($(this).index()==max_layer_count-1){bigSite.start_intro();}
								}
							});
						}
					});
					if(act_layer==max_layer_count){act_layer=1;}else{act_layer+=1;}
				}
			}
		},this));
	},
	
	close_intro:function(){
		var $intro_layer=$('div#intro_layer');
		if($intro_layer.length>0){$intro_layer.fadeOut(500,function(){$(this).remove();$('html,body').css({'overflow':'auto'});});}
	},
	
	resizeIntroIE:function(resize){
		if($.browser.msie){
			var $intro_layer=$('div#intro_layer');
			if($.browser.version=='7.0'){$intro_layer.css({'background-position':''+($(window).width()/2+50-this.ref_act_dim)+'px '+($(window).height()/2-50)+'px'})}
			if(resize){
				if($intro_layer.width()!=$(window).width()-this.ref_act_dim){
					$intro_layer.css({width:$(window).width()-this.ref_act_dim});
				}
				this.tmp.t=setTimeout("bigSite.resizeIntroIE(true)",500);
			} else {
				clearTimeout(this.tmp.t);
			}	
		}
	},

	commonInit:function(){
		this.cls=cls;
		$('div#b_ref_content').addClass('b_ref_content_'+this.cls);
		$('p#b_ref_title').addClass('b_ref_title_'+this.cls);
		$('p#b_ref_note').addClass('b_ref_note_'+this.cls);
		$('div#b_ref_new').addClass('b_ref_new_'+this.cls);
		$('div.descrTxt').addClass('descrTxt_'+this.cls);
		$(window).resize($.proxy(function(){
			if(this.isResize){return false;}
			//android orientation detect
			this.resizeWindow();
		},this));
		this.resizeWindow();
		this.addRefClickEvt();
		this.addDescrEvt();
	},

	filterRef:function(id){
		var $hide=$('div.ref,div.big_ref,div#news_box').not(':hidden');
		var $show={};
		if(id!='cat_all') {
			$show=$('div.ref[class*='+id+']');
		} else {
			$show=$('div.ref,div.big_ref,div#news_box');
		}
		$hide.fadeOut('slow',function(){
			$show.fadeIn('slow');
		});
	},

	resizeXtraItems:function(data){
		var $intro_layer=$('div#intro_layer');
		$('div.menu').css({width:this.ref_act_dim+2,height:this.menu_height});
		$('div#menu_top').css({width:this.ref_act_dim+2-40,left:'20px'});	//plus missing border
		$('li#menu_logo_item').css({width:this.ref_act_dim+2-40});		//plus missing border
		$('div.descrTxt').css({width:this.ref_act_dim-60-8});
		$('body').css({'background-size':this.ref_act_dim+2});
		if($intro_layer.length>0){$('html,body').css({overflow:'hidden'});}
		$intro_layer.css({width:$(window).width()-this.ref_act_dim-4,left:this.ref_act_dim+2});
	},

	resizeWindow:function(){
		this.isResize=true;
		if($('div#intro_layer').length>0){$('html,body').css({overflow:'auto'});}
		if($('div#descr_l:not(:hidden)').length>0) {$('div.exit_descr_l').click();if(!this.isAfterIntro){$('li#main_portfolio').click();}}
		var width=$(window).width();
		//set wrapper to minimum fit
		if(width<this.min_ref_per_row*this.ref_min_width) {
			width=this.min_ref_per_row*this.ref_min_width;
			$('div#wrapper').css('width',width);
		}else {
			$('div#wrapper').css('width','100%');
		}
		var act_ref_per_row=Math.floor(width/this.ref_min_width);
		this.ref_act_dim=Math.floor(width/act_ref_per_row)-2; //minus border
		if(this.ref_act_dim<104){this.ref_act_dim=104;}
//		this.menu_height=Math.ceil((this.ref_count+4+2)/(act_ref_per_row-1))*(this.ref_act_dim+2);	//4:big ref box, 2:description box || ref_per_row divide menu width
		this.menu_height=$('body').height();
		if($(window).height()>this.menu_height){this.menu_height=$(window).height();}
		this.resizeXtraItems({act_ref_per_row:act_ref_per_row});
		$('div.big_ref').css({'width':(this.ref_act_dim*2+2),'height':(this.ref_act_dim*2+2)});	//plus missing border
		$('div.ref').css({'width':this.ref_act_dim,'height':this.ref_act_dim});

		if(this.ref_per_row!=act_ref_per_row && $('div#news_box:hidden').length<1){
			$('div#news_box').remove();
			$(this.getNewsBox()).insertAfter('div.ref:eq('+(act_ref_per_row>4 ? act_ref_per_row*3-this.descr_pos_corr : this.descr_pos[act_ref_per_row] )+')');
			$('div#news_box').unbind('click').bind('click',$.proxy(function(e){
				var html='<div id="descr_l" class="refLayer">';
				html+='<div id="b_descr_l_content" class="';
				if(this.cls=='mobile'){html+='mobile_layer m_';}
				html+='news_pop">';
				if(this.cls=='mobile'){html+='<div class="m_layer_exit exit_menu"></div>';}
				html+='<p id="main_pop_title">'+news_box['title']+'</p><p class="main_pop_note">'+news_box['txt']+'</p></div></div>';
				$('body').append(html);
				var dim=$(e.currentTarget).offset();
				var css_init={top:dim.top,left:dim.left};
				var anim_init={width:($(window).width()-this.ref_act_dim-3),height:this.menu_height,left:(this.ref_act_dim+3)};
				if(this.cls=='mobile'){
					css_init={top:0,left:0};
					anim_init={width:$(window).width(),height:$('div#wrapper').height()-this.ref_act_dim-2,left:0};
				}
				var css=$.extend({},css_init,{display:'block',opacity:0.1,width:$(e.currentTarget).width(),height:this.ref_act_dim});
				var anim=$.extend({},anim_init,{opacity:1.0,top:0});
				$('body,html').animate({scrollTop:0},500,$.proxy(function(){
					$('div#descr_l')
					.css(css)
					.animate(anim,500,$.proxy(function(){
//						this.setLayerTitle();
						$('div#b_descr_l_content').fadeIn('slow',this.layer_callback({}));
					},this));
				},this));
			},this));
			this.ref_per_row=act_ref_per_row;
		} else if(this.ref_per_row!=act_ref_per_row) {
			this.ref_per_row=act_ref_per_row;
		}

		$('div#news_box').css({'width':this.ref_act_dim*2+2,'height':this.ref_act_dim});	//missing border(+2)
		//menu bottom fix
		if($(window).height()<580) {$('div#menu_bottom').css({top:'487px'})} else {$('div#menu_bottom').css({top:'auto'})}
		this.isResize=false;
		$('html,body').removeClass('hidden');
	},
	
//	setLayerTitle:function(){
//		var height=$('li#main_logo').height();
//		if(height!=undefined){
//			$('p#main_pop_title').css({height:height,lineHeight:(height-10)+'px'});
//		}
//	},

	getNewsBox:function(){
		var html='<div id="news_box"><div id="news_box_wrapper">';
		html+='<p id="news_box_title" class="news_box_title_'+this.cls+'">'+news_box['title']+'</p>';
		html+='<p id="news_box_note" class="news_box_note_'+this.cls+'">'+news_box['lead']+'</p>';
		html+='</div><div id="news_box_news" class="news_box_news_'+this.cls+'">';
		html+=this.txt[lang]['news'];
		html+='</div></div>';
		return html;
	},

	addDescrEvt:function(){
		$('div.ref,div.big_ref').unbind('click').click($.proxy(function(event){
			var $target=$(event.currentTarget);
			var ref_dim=$target.offset();
			var param={
				cls:'refLayer',
				top:ref_dim.top,
				left:ref_dim.left,
				dWidth:$(window).width()-this.ref_act_dim-3,
				dHeight:$(window).height(),
				dLeft:this.ref_act_dim+3,
				dTop:$(document).scrollTop()
			};
			this.getAjax('descr_big',$target.attr('id'),param);
		},this));
	},

	getAjax:function(cmd, id, param){
		var css={},anim={};
		if($('div#descr_l').length <1){
			$('body').append('<div id="descr_l" class="'+param.cls+'"></div>');
			css={display:'block',opacity:0.1,top:param.top,left:param.left,width:this.ref_act_dim,height:this.ref_act_dim};
			anim={width:param.dWidth,height:param.dHeight,opacity:1.0,top:param.dTop,left:param.dLeft};
		}
//		$('div#descr_l').css(css).addClass('aniani');
//		$('div#descr_l').delay(1000).css(anim);
//		$('body').append('<div class="testbox">jhgj</div>');
//
//		$('div.testbox').click(function(){
//			$(this).css({opacity:'1.0',height:'300px',width:'300px'});
//		});
//		$('div#descr_l').css({left:'10px',top:'10px',height:'200px',width:'200px',opacity:'1.0'});

		$('div#descr_l')
		.css(css)
		.animate(anim,500,$.proxy(function(){
			this.close_intro();
			$.ajax({
				type:'POST',
				url:'/page_types/multilang/site/ajax.php',
				dataType:'html',
				cache:false,
				data:{cmd:cmd,id:id},
				success:function(req){
					eval("site.show_"+cmd+"(req)");
				}
			});
		},this));
	},
	
	layer_callback:function(param){this.isAfterIntro=false;},
	
	show_layer:function(html){
		$('div#descr_l').html(html);
//		this.setLayerTitle();
		$('div#b_descr_l_content').fadeIn('slow',this.layer_callback({}));	
	},

	show_main_about:function(html) {
		this.show_layer(html);
		this.track_GA('/'+this.ga_lnk[lang]['lng']+'/'+this.ga_lnk[lang]['about_us']+'/');
	},

	show_main_solutions:function(html) {
		this.show_layer(html);

		$('dt').unbind('click').bind('click',function() {
			var $note=$(this).next('dd');
			var $this=$(this);
			$('dt').removeClass('collapse');
			if($note.is(':hidden')) {
				//$('dd').css({display:'none'});
				$('dd').slideUp(500);
				//$note.css({display:'block'});
				$note.slideDown(500);
				$this.addClass('collapse');
			} else {
				//$note.css({display:'none'});
				$note.slideUp(500);
			}
		});
		
		this.track_GA('/'+this.ga_lnk[lang]['lng']+'/'+this.ga_lnk[lang]['solutions']+'/');
	},

	show_main_contacts:function(html) {
		this.show_layer(html);
		this.track_GA('/'+this.ga_lnk[lang]['lng']+'/'+this.ga_lnk[lang]['contacts']+'/');
	},

	show_descr_big:function(html){
		if($('div#descr_l_content').length<1) {$('div#descr_l').html(html);}
		var $pic_wrapper=$('div#descr_l_pic_wrapper');
		this.descr_max_pic=$pic_wrapper.children('img').length;
		$('div#b_descr_l_pic_view').css({height:'460px', width:($(window).width()-this.ref_act_dim-3-20),'margin':($(window).height()-600)/2+'px 0'});
		$pic_wrapper.css({width:460*this.descr_max_pic+this.descr_max_pic*5, height:'460px'});
		$('div.b_descr_d_box').css({width:($(window).width()-this.ref_act_dim-3-55-95-120-4)/3});
		$('div#b_descr_l_content').fadeIn('slow',$.proxy(function(){
			
			$('div.exit_descr_l').unbind('click').bind('click',function() {
				$('div#descr_l').fadeOut('slow',function(){
					$(this).remove();
				});
			});
			
			this.track_GA('/'+$('div.b_descr_d_box').attr('id').replace(/_/g,'/'));
			
			if($('div#descr_l_pic_wrapper').width()<$('div#b_descr_l_pic_view').width()){
				return false;
			}else{
				$('div#b_right').css({display:'block'});
			}

			this.descr_pager=0;
			$('div.b_descr_l_pic_scrl').unbind('click').bind('click', $.proxy(function(event){
				if($pic_wrapper.is(':animated')) return;
				var position=$pic_wrapper.position().left;
				var offset=0;
				var do_offset=false;
				if($(event.currentTarget).attr('id')=='b_left' && this.descr_pager-1>=0){
					var offset_diff=$('div#descr_l_pic_wrapper').position().left%465;
					if(position+465<=0) {
						if(offset_diff!=0){
							offset=position-offset_diff;
						} else {
							offset=position+465;
						}
					} else {
						offset=0;
					}
					this.descr_pager--;
					do_offset=true;
				}else if($(event.currentTarget).attr('id')=='b_right' && this.descr_pager+1<this.descr_max_pic) {
					offset=-($pic_wrapper.width()-$(window).width()+this.ref_act_dim+20-this.descr_pager*465);
					if(offset<=-465) {
						offset=position-465;
						do_offset=true;
						this.descr_pager++;
					} else if(offset<=0) {
						offset=position+offset;
						do_offset=true;
						this.descr_pager++;
					}
				}
				if(do_offset) {
					$pic_wrapper.animate({left:offset},'slow',$.proxy(function(){
						if((-($pic_wrapper.width()-$(window).width()+this.ref_act_dim-this.descr_pager*465))>=0){
							$('div#b_right').css({display:'none'});
							$('div#b_left').css({display:'block'});
						}else if(offset==0) {
							$('div#b_left').css({display:'none'});
							$('div#b_right').css({display:'block'});
						} else {
							$('div.b_descr_l_pic_scrl').css({display:'block'});
						}
					},this));
				}
			},this));

		},this));
	},
	
	track_GA:function(url){
		_gaq.push(['_trackPageview', url]);
	},

	addRefClickEvt:function(){
		$('div.ref').not('.menu_box,.moreBtn').hover(function(e){
			$(e.currentTarget).children('img').delay(100).animate({opacity:0},250);
			$(e.currentTarget).children('div.descr_wrapper').children('div.descrTxt').delay(100).animate({bottom:'0px'},250);
		},function(e){
			$(e.currentTarget).children('img').delay(100).animate({opacity:1},250);
			$(e.currentTarget).children('div.descr_wrapper').children('div.descrTxt').delay(100).animate({bottom:'-60px'},250);
		});
	}

}

var mobileSite={
	descr_pos:{3:5,4:8,5:7,6:11},
	ref_min_width:106,
	descr_pos_corr:7,
	txt:{'hu':{'news':'hír','more':'Tovább'},'uk':{'news':'news','more':'More'}},
	menubox_pos:0,
	direction:'down',
	last_scroll_pos:0,
	isMenuboxChanging:false,
	isSelecting:false,
	
	init:function(){
		var menubox_html='<div id="pos0" class="ref menu_box"><img src="/images/logo.gif" /></div>';
		$('div.menu').append(menubox_html);
		$('div.ref:eq(1)').insertAfter('div.menu_box:not(:hidden)');
		$('div.menu').css({'background-color':'#1B1C20'}); //???
		this.addMoreBtn();
		this.commonInit();
		$(window).scroll($.proxy(function(){
			if($('div#descr_l:not(:hidden)').length>0) {$('div.exit_descr_l').click();}
			this.putMenuChangeEvt();
		},this));
//		this.hideURLbar();
		this.addMenuboxClickEvt();
	},
	
	onOrientationchange:function(){
		this.menubox_pos=-1;
		if($('div#descr_l:not(:hidden)').length>0) {$('div.exit_descr_l').click();}
		if($('div.m_layer_exit').length>0){$('div.m_layer_exit').click();}	
	},

	layer_callback:function(param){
		$('div.m_layer_exit').unbind('click').bind('click',function(){
			$('div#descr_l').fadeOut('slow',function(){
				if($('div#descr_l').length>0){$('div#descr_l').remove();$('body').animate({scrollTop:0},250);}
			});
		});
	},
	
	addMoreBtn:function(){
		if($('div.preloaded').length>0){
			var html='<div class="ref moreBtn"><span><span>'+this.txt[lang]['more']+'...<span></span></div>';
			$(html).insertBefore('div#footer');
			$('div.moreBtn').unbind('click').bind('click',$.proxy(function(){
				$('div.preloaded:lt(10)').children('img').attr('src',function(index,attr){return $(this).attr('alt')}).end().removeClass('preloaded').css({display:'block'});
				if($('div.preloaded').length<1){$('div.moreBtn').remove();}
				this.resizeWindow();
			},this));
		}
	},

	putMenuChangeEvt:function(){
		if(this.isMenuboxChanging) {return false;}
		clearTimeout(this.tmp.t);
		this.tmp.t=setTimeout($.proxy(function(){this.reinstateSite()},this),500);
	},
	
	addDescrEvt:function(){
		$('div.descr_wrapper,div.big_ref').unbind('click').click($.proxy(function(event){
			var $target=$(event.currentTarget);
			var ref_dim=$target.offset();
			var param={
				top:ref_dim.top,
				left:ref_dim.left,
				dWidth:$(window).width(),
				dHeight:window.innerHeight,
				dLeft:0,
				dTop:$(document).scrollTop()
			};
			this.getAjax('descr_mobile',$target.attr('id'),param);
		},this));
	},
	
	addRefClickEvt:function(){
		$('div.ref').not('.menu_box,.moreBtn').children('img').unbind('click').bind('click',$.proxy(function(event){
			$(event.currentTarget).delay('100').animate({'left':this.ref_act_dim},250).delay('2000').animate({'left':'0px'},250);
		},this));
	},
	
	addMenuboxClickEvt:function(){
		$('div.ref, div.exit_menu').not('.moreBtn').unbind('click');
		$('select').unbind('mouseover').bind('mouseover',$.proxy(function(){
			this.isSelecting=true;
		},this));
		$('div.menu_box, div.exit_menu').bind('click', $.proxy(function(){
			$('div.ref').not('.menu_box,.moreBtn').children('img').unbind('click');
			if($('div#expand_menu:hidden').length>0){//SHOW
				$('div.menu_box').css({'border-color':'white'});
				$('div#expand_menu')
				.css({display:'block',opacity:0.1,top:$('div.menu_box').offset().top,left:$('div.menu_box').offset().left,width:this.ref_act_dim+2,height:this.ref_act_dim+2})
				.animate({width:this.ref_act_dim*3+6,height: this.ref_act_dim*2+4,opacity:1.0},250,$.proxy(function(){
					$('div#menu_content').fadeIn('slow',$.proxy(function(){
						var $select=$('li#category_filter select')[0];
						$select.disabled=false;
						$($select).change($.proxy(function(){
							if($('div#expand_menu').not(':hidden').length>0) {$('div.exit_menu').click();}
							$('div#sel_name').html($($select).children('option:selected').text());
							this.filterRef($($select).val());
						},this));
					},this));
				},this));
				
				$('li.menu_link').unbind('click').bind('click',$.proxy(function(e){
					var id=$(e.currentTarget).attr('id');
					var param={
						cls:'menuLayer',
						top:0,
						left:0,
						dWidth:$(window).width(),
						dHeight:$('div#wrapper').height()-this.ref_act_dim-2,
						dLeft:0,
						dTop:0
					};
					$('body').animate({scrollTop:0},500,$.proxy(function(){
						this.getAjax('main_'+id,'mobile',param);
					},this));
				},this));
				
			} else {//HIDE (MENU)
				this.isSelecting=false;
				$('div#menu_content').fadeOut(500,$.proxy(function(){
					$('div#expand_menu')
					.animate({width:this.ref_act_dim,height:this.ref_act_dim,opacity:0.1},250,function(){
							$(this).css({display:'none'});
							$('div.ref').css({'border-color':'black'});
							site.addRefClickEvt();
						});
				},this));
			}
		},this));
	},
	
	filterRef:function(id){
		var $show={};
		var $hide=$('div.ref,div.big_ref,div#news_box').not(':hidden');
		$('div#wrapper').delay(250).fadeOut('slow',$.proxy(function(){
			$hide.css({display:'none'});
			if(id!='cat_all') {//FILTER
				if($('div.menu').length>0){
					$('div.menu').children().insertBefore('div.big_ref');
					$('div.menu').children().remove();
					$('div.menu').css({display:'none'});
				}
				$show=$('div.ref').filter('.'+id+',.menu_box');
				$show.filter('.preloaded').removeClass('preloaded').children('img').attr('src',function(index,attr){return $(this).attr('alt')});
				this.resizeWindow();
			} else {//ALL
				$('div.ref:lt(2)').appendTo('div.menu');
				$('div.menu').css({display:'block'});
				$show=$('div.ref:not(.preloaded),div.big_ref,div#news_box,div.menu');
			}
			this.menubox_pos=-1;	//re-direct menu_box
			this.resizeWindow();
			$show.css({display:'block'});
			$('div#wrapper').fadeIn('slow');
		},this));
	},

	show_descr_mobile:function(html){
		if($('div#descr_l_content').length<1) {$('div#descr_l').html(html);}
		var $pic_wrapper=$('div#descr_l_pic_wrapper');
		this.descr_max_pic=$pic_wrapper.children('img').length;
		var descr_width=0,descr_height=0,pic_height=0,pic_width=0;
		var orientation=window.orientation;
		if(window.orientation!=undefined && (orientation==90 || orientation==-90)) {
			//LANDSCAPE
			pic_height=window.innerHeight;
			pic_width=pic_height;
			descr_width=$(window).width()-pic_width-5;
			descr_height=window.innerHeight-25;
		} else {
			//PORTRAIT
			pic_width=this.ref_per_row*(this.ref_act_dim+2);
			pic_height=pic_width;
			descr_width=pic_width-5;
			descr_height=window.innerHeight-pic_height-25;
		}
		
		$('div#descr_l_pic_view').css({height:pic_height, width:pic_width});
		$pic_wrapper.css({width:pic_width*this.descr_max_pic+8, height:pic_height})
		.children('img').css({width:pic_width,height:pic_height});

		$('div#descr_l_descr').css({height:descr_height,width:descr_width});
		$('div#descr_l_content').fadeIn('slow',$.proxy(function(){

			$('div.exit_descr_l').unbind('click').bind('click',function(){
				$('div#descr_l').fadeOut('slow',function(){
					$(this).remove();
				});
			});
			if($('div#descr_l_pic_wrapper img').length<2){
				return false;
			} else {
				$('div#right').css({display:'block'});
			}

			$('div.descr_l_pic_scrl').unbind('click').bind('click', $.proxy(function(event){
				if($(event.currentTarget).attr('id')=='left'){
					if(this.descr_pager-1>=0){
						this.descr_pager-=1;
					}
				}else{
					if(this.descr_pager+1<this.descr_max_pic){
						this.descr_pager+=1;
					}
				}
				
				$pic_wrapper.animate({left:pic_width*this.descr_pager*-1},'slow',function(){
					var $img=$('div#descr_l_pic_wrapper img');
					if($pic_wrapper.position().left==-($img.first().width()*($img.length-1))){
						$('div#right').css({display:'none'});
						$('div#left').css({display:'block'});
					}else if($pic_wrapper.position().left==0){
						$('div#left').css({display:'none'});
						$('div#right').css({display:'block'});
					}else{
						$('div.descr_l_pic_scrl').css({display:'block'});
					}
				});
			},this));
			$('div#descr_l_pic_view').touchwipe({
				wipeLeft: function() { $('div.descr_l_pic_scrl[id="right"]').click() },
				wipeRight: function() { $('div.descr_l_pic_scrl[id="left"]').click() },
				wipeUp: function() { /* do nothing */ },
				wipeDown: function() {/* do nothing */ },
				min_move_x: 20,
				min_move_y: 20,
				preventDefaultEvents: true
			});
		},this));
	},
	
	reinstateSite:function(){
		this.isMenuboxChanging=true;
		var act_scroll_pos=$('body').scrollTop();
		var corr_pos=0;
		var menuPos=0;
		var $sel_ref={};
		var menubox_act_pos=Math.round(act_scroll_pos/this.ref_act_dim);
		var dist=act_scroll_pos%this.ref_act_dim;
		if(!this.isSelecting){
			if(dist<=this.ref_act_dim/2){//DIRECTION:UP
				corr_pos=act_scroll_pos-dist;
				menubox_act_pos=Math.round(corr_pos/this.ref_act_dim);
				menuPos=this.getMenuPos(menubox_act_pos);
				$sel_ref=$('div.ref:not(":hidden"):eq('+menuPos+')');
			} else {//DIRECTION:DOWN
				corr_pos=act_scroll_pos+(this.ref_act_dim-dist);
				menubox_act_pos=Math.round(corr_pos/this.ref_act_dim);
				menuPos=this.getMenuPos(menubox_act_pos);
				$sel_ref=$('div.ref:not(":hidden"):eq('+menuPos+')');
			}			
		}else{
			$sel_ref=$('div.menu_box');
			this.isMenuboxChanging=false;
		}

		if($('div.mobile_layer').length<1){
			$('body').stop(true,true).animate({scrollTop: $sel_ref.offset().top},125,$.proxy(function(){
				if(!this.isSelecting){
					this.changeMenubox(menubox_act_pos,$sel_ref);
				}
			},this));
		}else{
			$('div.m_layer_exit').fadeOut(500,$.proxy(function(){
				$('div.m_layer_exit').css({top:$(document).scrollTop()}).fadeIn(500);
				this.isMenuboxChanging=false;
			},this));
		}

	},

	getMenuPos:function(act_pos){
		var menuPos=0;
		if($('div.menu').is(':hidden')){
			menuPos=act_pos*this.ref_per_row;
		}else{
			if(act_pos<1){return 0;} else if(act_pos<2){return 1;}	//because div1 packed into menu div
			menuPos=act_pos*this.ref_per_row-this.descr_pos_corr+1;
			if((this.ref_per_row<5 && act_pos<4) || (this.ref_per_row>4 && act_pos<3)){
				menuPos+=2;	//plus news_box that we substract before
			}
		}
		return menuPos;
	},
	
	changeMenubox:function(menubox_act_pos,$sel_ref){
		if($sel_ref.hasClass("moreBtn")){this.isMenuboxChanging=false;return false;}
			var prev_idx=$('div.menu_box').index()-1;
			if(prev_idx<0){prev_idx=0;}
			if(menubox_act_pos!=this.menubox_pos || $('div.ref:eq('+prev_idx+')').offset().top==$('div.menu_box').offset().top && $('div.menu_box').offset().top!=0){
				if($('div#expand_menu:not(:hidden)').length>0 && menubox_act_pos!=this.menubox_pos) {$('.exit_menu').click();}
				var $menubox=$('div.menu_box');
				$($menubox,$sel_ref).animate({opacity:0.1},125,$.proxy(function(){
					$($menubox,$sel_ref).css({display:'none'});
					var ref_html=$sel_ref.html();
					var ref_cls=$sel_ref.attr('class');
					var cat_cls="";
					$(ref_cls.split(' ')).each(function(i,data){
						if(data.search(/cat_/i)>-1) cat_cls=data;
					});
					var menubox_html=$menubox.html();
					$menubox.removeClass('menu_box').addClass(cat_cls+' hidden').html(ref_html);	//because inherit the dimensions too
					$sel_ref.removeClass(cat_cls).addClass('menu_box hidden').html(menubox_html);
					$('div.hidden').css({display:'block'}).animate({opacity:1.0},125,$.proxy(function(){
						$('div.hidden').removeClass('hidden');
						$('div.ref').children('img').animate({left:0},250);
						this.addDescrEvt();
						this.addRefClickEvt();
						this.addMenuboxClickEvt();
						this.menubox_pos=menubox_act_pos;
						this.isMenuboxChanging=false;
//	CASE WHEN STILL NOT POSITIONING RIGHT
//	if($('div.ref:eq('+prev_idx+')').offset().top==$('div.menu_box').offset().top && $('div.menu_box').offset().top!=0){
//		this.changeMenubox(menubox_act_pos,$sel_ref);
//	}
					},this));
				},this));
			} else {
//	CASE WHEN STILL NOT POSITIONING RIGHT
//	if($('div.ref:eq('+prev_idx+')').offset().top==$('div.menu_box').offset().top && $('div.menu_box').offset().top!=0){
//		this.changeMenubox(menubox_act_pos,$sel_ref);
//	}
				this.isMenuboxChanging=false;
			}
	},

//	hideURLbar:function(){
//		setTimeout(function() {
//			window.scrollTo(0, 1);
//		}, 0);
//	},

	resizeXtraItems:function(data){
		$('div.menu').css({'width':this.ref_act_dim+2,'height':this.ref_act_dim*2+4});
		$('div.menu_box').css({'width':this.ref_act_dim,'height':this.ref_act_dim});
		$('div#footer').css({'width':this.ref_act_dim*data.act_ref_per_row+data.act_ref_per_row*2-2,'height':this.ref_act_dim});
		$('div#back_to_top').unbind('click').bind('click',$.proxy(function(){
			$('body').animate({scrollTop:0},500,$.proxy(function(){
				this.putMenuChangeEvt();	
			},this));
			
		},this));
		$('div#descr_layer').css({'width':this.ref_act_dim,'height':this.ref_act_dim});
		this.putMenuChangeEvt();
	},

	show_main_solutions:function(html) {
		this.show_layer(html);

		$('dt').unbind('click').bind('click',function() {
			var $note=$(this).next('dd');
			var $this=$(this);
			$('dt').removeClass('collapse');
			if($note.is(':hidden')) {
				$('dd').css({display:'none'});
				$('body,html').animate({scrollTop:$(this).offset().top},500,function(){
					$note.css({display:'block'});
					$this.addClass('collapse');
				});
			} else {
				$note.css({display:'none'});
			}
		});
	}
}

$(document).ready(function() {
	if(window.orientation!=undefined && ($(window).width()<500 || $(window).height()<500)) {
		//MOBIL SITE
		site=$.extend({},bigSite,mobileSite);
	} else {
		//BIG SITE
		site=bigSite;
	}
	site.init();
});
