$(document).ready(function(){
						   mtop.init();
                           fb_photolink();
						   });
$(window).load(function(){
			main_boxes.init();
			galleries.init();
			if($('.facebook').is('div')){
				load_fb();
				}
			if($('#video_yt').is('div')){
				load_yt();
				}
				box_style.init();
			 $('#footer_container').css('top',$(document).height());
			
	$(window).resize(function(){
				window.setTimeout("shiftPosition()");
				window.setTimeout("setFooter()");
				window.setTimeout("checkRightBoxes()");
			});
		});



var galleries={
	init : function(){
		$('.gallery').each(function(){
								  if($(this).attr('id')=='els_brand_all'){
									  window.setTimeout("galleries.start_gallery('els_brand_all')",1500);	 
									  }
								  else{
									  galleries.start_gallery($(this).attr('id'));	 
									  }	
								  });
		},
	start_gallery : function(el){
			$('#'+el).find('.els_gallery').cycle({ 
				fx:   'fade', 
				speed:  1500,
				timeout: 6500, 
				startingSlide: 0,
				after : function(curr,next,opts){
							galleries.set_nav(el,$('#'+el).find('.nav_gallery a').eq(opts.currSlide));
				}
			 }); 
			$('#'+el).find('.nav_gallery a').each(function(i){
														   $(this).click(function(){ 
																	$('#'+el).find('.els_gallery').cycle(i);
																	galleries.set_nav(el,$(this));
																	return false; 
																}); 
														   });	
			$('#'+el).find('a').attr('title','');
		},
	set_nav : function(el,linknav){
			  $('#'+el).find('.nav_gallery a').each(function(){
															 $(this).removeClass('on');
															 });
			  $(linknav).addClass('on');
		}	
	
}

var mtop={
		prev_ls : null,
		init : function(){
				$('.btn_mright').click(function(){
												mtop.mright($(this).attr('id'));	  
										});	
				$('#become_fan>li>ul>li>a').hover(function(){
														   $(this).find('img').css('top','-27px');
														   },
														   function(){
															$(this).find(' img').css('top','0');   
															});
				$('#quicknav').hover(function(){},
									function(){
										$('#quicknav').fadeOut('fast');
										});
				$('#open_qn>a').hover(function(){
											   $(this).find('img').css('top','-35px');
											   },
											   function(){
												 $(this).find('img').css('top','0');   
												});
				$('#open_qn>a').click(function(){
											   $('#quicknav').show();
											   });
				$('#close_quicknav>a').click(function(){
											   $('#quicknav').hide();
											   });
				
			},	
		mright	: function(elid){
				  targetel=$('#'+elid).next('ul');
				  type=elid.split('_');
				  if($('#close_'+type[1]).is('a')) return;
				  if(mtop.prev_ls!=null){
					  mtop.mrigth_hide(mtop.prev_ls,$('#btn_'+mtop.prev_ls).next('ul'));
					  }
	
				   $(btn_close).insertBefore($('#'+elid));
				   $('#close_'+type[1]).click(function(){
											mtop.mrigth_hide(type[1],targetel);
											  });
				  mtop.prev_ls=type[1];
				  mtop.mrigth_show(type[1],targetel);
			},
		mrigth_show : function(type,el){
						if(type=='storelocator'){
					   	 el.show();
					   	 }else{
							el.find('li').show();
						}   
			},
		mrigth_hide : function(type,el){
						$('#close_'+type).remove();
						if(type=='storelocator'){
							el.hide();
						}else{
							el.find('li:not(.selected)').hide();
						}   
			}	
}






var box_style={
		init : function(){
				$('.item').each(function(){
									var type=$(this).attr('class').split(' ');
									var column=type[1].split('_')[1].substr(0,3);

									if(!type[2]){
										//$(this).find('.imglink').attr('title','');
										$(this).hover(function(){
															box_style.show($(this).attr('id'));  
															   },
															   function(){
															box_style.hide($(this).attr('id'));	   
															});
										}
									});
		},
		show : function(id){
				var box=$('#'+id);
				var type=box.attr('class').split(' ');
				var column=type[1].split('_')[1].substr(0,3);

				column!=170 ? ico_godetail='' : ico_godetail='';
				var url=box.find('.p_content a.imglink').attr('href');	
				var theImg=box.find('.p_content a.imglink');
				var fdr_height=box.find('.p_content a.imglink>img').height();
				var fdr_width=box.find('.p_content a.imglink>img').width();
				var icodetail='<div id="ico_godetail_'+column+'"><a href="'+url+'">'+ico_godetail+'</a></div>';
				var fdr='<div id="fdr_boxes">&nbsp;</div>';
				theImg.append(fdr);
				$('#fdr_boxes').css('height',fdr_height);
				$('#fdr_boxes').css('width',fdr_width);
				$('#fdr_boxes').fadeTo('fast',0.1);
				if(column==170){
					$('#'+id).find('.p_content').append(icodetail);
					$('#'+id).find('.txt_box_vis').attr('class','txt_box_vis_on');
					}	
				if(box.find('.txt_box').is('div')){
					$('#'+id).find('.txt_box').append(icodetail);
					box.find('.txt_box').width(box.width()-75);
					box.find('.txt_box').show();
					}
		},
		hide : function(id){
				var box=$('#'+id);
				var type=box.attr('class').split(' ');
				var column=type[1].split('_')[1].substr(0,3);
				box.find('#ico_godetail_'+column).remove();
				box.find('#fdr_boxes').remove();
				box.find('.txt_box_vis_on').attr('class','txt_box_vis');
				if(box.find('.txt_box').is('div')){
					box.find('.txt_box').hide();
					}
		}
}






var main_boxes={
	nr_items : 0,
	init : function(){
			main_boxes.nr_items=$('#container_boxes>.item').length;
			$('#container_boxes>.item').each(function(i){
									$(this).attr('id');
									$(this).find('a').attr('title','');
									if(i==main_boxes.nr_items){
										shiftPosition;
										}
									});
			checkRightBoxes();	
		}
}

Array.max = function(array){
   		 return Math.max.apply( Math, array );
		}; 
var leftpos=[];

function checkRightBoxes(){
		maxLeft=Array.max(leftpos);
		if(maxLeft<550){
			$('#nav_top_left').css('width');
			}
		else{
			$('#nav_top_left').css('width');
			}	
		

		leftpos=[];
}

