﻿var bg_image_data = new Array();
var imgs = new Array();
var bg_image = new Array();
(function($) {           
 
        $( "#page #arow_left" ).live('click',(function() {
                
                 /*  select = $("#background .selected"); 
                   prev = select.prev();
                   if (prev.attr('src')==undefined)                       
                       prev = $("#background img:last");                   
                   
                       prev.css({'top':0,'left':0,'position':'absolute'});                   
                       
                       select.removeClass('selected');
                       prev.addClass('selected');
                       //$(window).resize();
                       
                   var theWindow  = jQuery(window);   
                
                    if ( (theWindow.width() / theWindow.height()) <= 1.4 ) {
                        prev.css({'width':'auto','height':theWindow.height(),'left':theWindow.width()+10});
                         
                    } else {
                        prev.css({'width':theWindow.width(),'height':'auto','left':theWindow.width()+10});
                        
                    }
                        //alert("z");
                        select.animate({'left':0},'slow');
                        prev.animate({'opacity':1},'slow');  
                   return false;
                       
                                       */        
                   })); 
        $( "#page #arow_right" ).live('click',(function() {                    
                 /*  select = $("#background .selected"); 
                   next = select.next();
                   if (next.attr('src')==undefined)                       
                       next = $("#background img:first");                   
                   
                       next.css({'top':0,'left':0,'position':'absolute'});                   
                       
                       select.removeClass('selected');
                       next.addClass('selected');
                       //$(window).resize();
                       
                   var theWindow        = jQuery(window);
      
                
                    if ( (theWindow.width() / theWindow.height()) <= 1.4 ) {
                        next.css({'width':'auto','height':theWindow.height(),'left':theWindow.width()+10});
                         
                    } else {
                        next.css({'width':theWindow.width(),'height':'auto','left':theWindow.width()+10});
                        
                    }
                        //alert("z");
                        select.animate({'left':0},'slow');
                        next.animate({'left':theWindow.width()},'slow');  
                   return false;
                  
                      // $("#background").css({'background-image':'url('+bg_image[parseInt($("#background").attr('index'))]+')'});  
                      // $("#background").attr('index',parseInt($("#background").attr('index'))+1);
                    
                      */
                   })); 
                   
                   
                   
                   
     /*  $( ".resize").mousedown(function(e) {
            p=$(this);
                e.preventDefault();    
                $(document).mousemove(function(e){
                    //alert(p.attr("id"));
                    if (p.hasClass('y')){
                        //alert($('body').width());
                        if(e.pageY>$('body').height()-108){
                            $(document).unbind('mousemove'); 
                            return;
                        }
                        $("#footer").css({height:$('body').height()-e.pageY-10,bottom:0}); 
                        $("#footer_h").css({top:e.pageY-$("#footer").height()});
                        $(".olControlMousePosition").css({top:e.pageY-35,right:0});
                        $(".olLayerGoogleV3.olLayerGooglePoweredBy ").css({top:e.pageY-20 });
                        $("#footer #tabs ul").css({bottom:$("#footer").height()-9});
                        $("#ts_info #chart").css({bottom:0});
                        chart.setSize(chartWidth = $("#ts_info").width() ,chartHeight = $('#footer').height()-2);
                        chart.redraw;
                        
                    }
                    else if(e.pageX>205){
                        $("#left").css({width:e.pageX});
                        $("#footer").css({left:e.pageX});                        
                        $(".wind2 #menu").css({width:e.pageX-20});
                        $(".olControlPanZoom").css({left:e.pageX-115});
                    }else{
                         $(document).unbind('mousemove'); 
                    }
                    });
                         
            })*/
        
      /*  $( ".resize").mouseup(function() {
                $(document).unbind('mousemove'); 
            })
       */
        
       
})(jQuery);

jQuery(function() {             
        
        
            
       
            
        jQuery("#shops_child").next().height(jQuery("#shops_child").height()) ;
        
        
        
      var theWindow        = jQuery(window),
            $bg              = jQuery("#background .selected"),
            aspectRatio      = $bg.width() / $bg.height();
    
        function resizeBg() {
			if (jQuery("div").is("#news_cont")){
                
            }    
                //jQuery("#news_cont").css({'top':-22,'bottom':0},"fast");
                if ( (theWindow.width() / theWindow.height()) <= 1.4 ) {
					$bg.css({'width':'auto','height':theWindow.height()});
                } else {
                    $bg.css({'width':theWindow.width(),'height':'auto'});
					
                }
                
            
                if ((jQuery("div").is("#news_cont")) && (!jQuery("div").is("#shops_child_cont"))){
                    //jQuery("#content").css({'top':-22},"fast");
                    jQuery("#content").height(jQuery(window).height()-150);
                    //jQuery("#news_cont").height(jQuery(window).height()-200) ;
                    var de = document.documentElement;
                    
                    $("#news_cont").css({'height':de.clientHeight/1.45}); 
                    //alert();
                    $("#soc_link_black").css({'bottom':de.clientHeight-$("#news_cont").height()-$("#news_cont").offset().top}); 
                    //jQuery(".scroll-pane").height(jQuery(window).height()-150);
                    
                }
                
                if (jQuery("#primary").hasClass("shop_list") ){
                    //alert($(window).height()-$("#primary").offset().top);
                    jQuery("#primary").css({'height':$(window).height()-$("#primary").offset().top+"px"}); 
                    
                }
                
                if (jQuery("div").is("#contact_cont") ){
                    //alert($("#contact_cont").offset().top);
                    $("#soc_link_black").css({'top':$("#contact_cont").height()}); 
                }
                
        }
    
        theWindow.resize(function() {
 
                resizeBg();                
                jQuery("#table_menu td:not(:first)").each(function(){ //выравнивание высоты верхнего меню            
                    jQuery(this).find('img').height(jQuery('#table_menu td:first img').height());                    
                });
                    
        }).trigger("resize");
        
       
            
       /* $( "#scroll").live('mousedown',(function(e) {
                    //alert(jQuery('#shops_child_cont').offset().top);    
                    e.preventDefault();    
                    jQuery(document).mousemove(function(e){
                       
                        
                        //alert($('body').width());
                        if((e.pageY>jQuery('#shops_child_cont').height()+jQuery('#shops_child_cont').offset().top) ){
                            jQuery(document).unbind('mousemove'); 
                            return;
                        }
                        else if(e.pageY>jQuery('#shops_child_cont').offset().top){
                            // alert(jQuery("#shops_child_cont .text").html());
                            y1=jQuery("#scroll").offset().top-jQuery('#shops_child_cont').offset().top;
                            if (y1<=0){
                                //jQuery("#scroll").css({'top':jQuery('#shops_child_cont').offset().top});
                                //jQuery(document).unbind('mousemove'); 
                                return false;
                            }
                             delta = jQuery("#shops_child_cont .text").height() / 50;                             
                             jQuery("#scroll").css({'top':e.pageY-jQuery('#shops_child_cont').offset().top-25});
                             
                             to = Math.round(delta * (-1));
                             jQuery("#shops_child_cont .text").html(jQuery("#scroll").offset().top-jQuery('#shops_child_cont').offset().top);
                             //alert();
                             //jQuery("#shops_child_cont .text").css({'top':to});
                             //document.getElementsByClassName('text').style.top = to+"px";
                             //$("#footer").css({height:$('body').height()-e.pageY-10,bottom:0}); 
                        }else{
                             jQuery(document).unbind('mousemove'); 
                        }
                        });
           }));
        $( "#scroll").live('mouseup',(function(e) {
                jQuery(document).unbind('mousemove'); 
           }));
*/
});




/*function scroll_down(p)
{
           
    //p=jQuery(this);
    alert(p.attr('id'));
    //e.preventDefault();    
    jQuery(document).mousemove(function(e){
       
        
            //alert($('body').width());
        if(e.pageY>jQuery('#shops_child_cont').height()-50){
            jQuery(document).unbind('mousemove'); 
            return;
        }
        
            
        
        else if(e.pageY>205){
            
        }else{
             jQuery(document).unbind('mousemove'); 
        }
        });
}
*/

function show_shop(element)
{
    if (element.hasClass("selected"))
        return;
    else{    
        de = document.documentElement;
        jQuery("#shops_child li").removeClass("selected");
        element.parent().addClass("selected");
        jQuery("#shops_child").next().html();    
        //alert(jQuery("#shops_child_cont").attr('id'));
        //jQuery("#shops_child_cont").css({"width":de.clientwidth});
        //jQuery("#shops_child").next().animate({'width':0},{duration:1000, easing: 'easeOutQuad'}).animate({'width':"70%"},{duration:1500, easing: 'easeOutCirc'});
        
        jQuery("#shops_text").html(element.next().html());
        //Cufon.replace('#shops_text', { fontFamily: 'OCR One Cyr' });
        //$('.scrollbar').scrollbar();
        
        //$('.scrollbar').jScrollPane();
        
        
        jQuery("#shops_text").css({'padding':'0'});
        //$('#container2').scrollbar('repaint');
            
    }
    
}



function mouseleave(element){
    //alert($(element).attr('src'));
        str = jQuery(element).attr('src').substring(jQuery(element).attr('src').lastIndexOf('/')+1,jQuery(element).attr('src').length);
        //alert(str);
        if(str.indexOf('_hover') + 1) 
            str=jQuery(element).attr('src').substring(0,jQuery(element).attr('src').lastIndexOf('/')+1)+str.split('_')[0]+'.png';    
        else     
            str=jQuery(element).attr('src').substring(0,jQuery(element).attr('src').lastIndexOf('/')+1)+str.split('.')[0]+'_hover.png';
        jQuery(element).attr('src',str);                
        if(window.opera) {
            jQuery(element).parent().parent().css({'border-left': '1px solid #FFF'});
            jQuery(element).parent().parent().next().css({'border-left': '1px solid #FFF'});
        }    
}

function mouseenter(element){
    //alert($(element).attr('src'));
    str = jQuery(element).attr('src').substring(jQuery(element).attr('src').lastIndexOf('/')+1,jQuery(element).attr('src').length);
    
    if(str.indexOf('_hover') + 1) 
        str=jQuery(element).attr('src').substring(0,jQuery(element).attr('src').lastIndexOf('/')+1)+str.split('_')[0]+'.png';    
    else     
        str=jQuery(element).attr('src').substring(0,jQuery(element).attr('src').lastIndexOf('/')+1)+str.split('.')[0]+'_hover.png';
    jQuery(element).attr('src',str);
    if(window.opera) {
        jQuery(element).parent().parent().css({'border-left': '0px solid'});
        jQuery(element).parent().parent().next().css({'border-left': '0px solid'});
    }    
}

function news_item_close()
{
    
  
  
    jQuery('.news_item').show(0);
    //jQuery('#news_item_cont').hide();
    jQuery('#ttt').show(0);
    //jQuery("#ttt").css({"padding-left":jQuery("#table_menu img:first").width(),"padding-right":jQuery("body").width()-jQuery("#table_menu img:last").offset().left-20});
    
    jQuery('#ttt').animate({"marginLeft":0,"width":$(window).width()-($(window).width()-jQuery("#table_menu img:last").offset().left)-jQuery("#table_menu img:first").width(),height:jQuery('#news_close').attr("ttt")},1000);
    
    jQuery('#news_item_cont').animate({left:$(window).width()},1000,function(){
       $(this).hide().html("");
      
    });
    jQuery('#news_close').hide();
    
    
     
        //jQuery("#news_item_cont").css({"padding-left":jQuery("#table_menu img:first").width(),"padding-right":jQuery("body").width()-jQuery("#table_menu img:last").offset().left,"width":jQuery("body").width()-jQuery("#table_menu img:last").offset().left-jQuery("#table_menu img:first").width()});
        
    
}

function news_item_click(element){
    //alert($(element).html());
    
    var slideTo	= -$(window).width() + 'px';
	//jQuery('#ttt').stop().animate({left : slideTo},1000);
    //alert(element.attr("id"));
    $.post("#", {"news_id":element.attr("id")}, function(data){                           
            if (data)               
            {
                //  alert(data);
                jQuery('#news_close').attr("ttt",jQuery('#ttt').height());
                jQuery('#news_item_cont').html('<br />'+data).css({left:$(window).width(),opacity:1,"top":0,"width":$(window).width()}).show();
              

                jQuery('#ttt').animate({"marginLeft":slideTo,"width":$(window).width()-($(window).width()-jQuery("#table_menu img:last").offset().left)},800,function(){
                   //$(this).css({display:"none"});
                   $(this).css({width:2,height:jQuery('#news_item_cont').height()});
                });

                jQuery('#news_item_cont').animate({"left":jQuery("#table_menu img:first").width(),"width":$(window).width()-($(window).width()-jQuery("#table_menu img:last").offset().left)-jQuery("#table_menu img:first").width()},1000);

                jQuery('#news_close').height(jQuery('#news_cont').height()).css({"top":0}).show(1000);
                
                jQuery('#news_close img').css({"marginTop":jQuery('#news_cont').height()/3});
             
                
                $("#news_item_cont a:has(img)").lightbox();
            }
        });
    return;        
  
}
function redraw_menu()
{
        jQuery("#table_menu td:not(:first)").each(function(){ //выравнивание высоты верхнего меню
            
            jQuery(this).find('img').height(jQuery('#table_menu td:first img').height());
      
        });
        
    
    
    for (i=1;i< bg_image.length;i++)
    {
        if (bg_image[i] != $("#background .selected").attr('src')){
            //alert(bg_image[i]);
            //$("<img src='".bg_image[i]."' />").appendTo("#background");
            
            $("#background").append("<img class='bg_img'  src='"+bg_image[i]+"' />");
            //img = new Image($("#background .selected").height(),$("#background .selected").width()).src=bg_image[i];
        
        }
    }
    return;    
        
}
/*
function thumb(img, width, height)
{
    var x_ratio = width / img.width;
    var y_ratio = height / img.height;

    var ratio = Math.min(x_ratio, y_ratio);
    var use_x_ratio = x_ratio<y_ratio ? 1 : 0;

    var w = use_x_ratio ? width : Math.ceil(img.width * ratio);
    var h = !use_x_ratio ? height : Math.ceil(img.height * ratio);

    img.width = w;
    img.height = h;
}*/




function preload() {
    
    var i=0;
    jQuery("#table_menu tr td:first").css({"background":"none"});
    jQuery("#table_menu img").each( function (){   
            imgs[this.name+'_hover'] = new Image(this.height,this.width);
            imgs[this.name+'_hover'].src=this.src.replace("/\.(.*?)$/",'_hover.$2');
            //alert(imgs[this.name+'_hover'].src);
    });
    //style="bottom:0px; border:solid 2px #000;"
    //shop_list
    if(jQuery(".shop_list").length > 0 )
    {
    
    //$(".shop_list").css({'bottom':"0px"}); 
   // alert($(".shop_list").html());
    }
    
    jQuery("#preload").animate({"opacity":0},1000,function(){
        jQuery(this).hide();
        
         if(jQuery("#news_cont").length > 0 )
            {
                //alert(jQuery("body").width()-jQuery("#table_menu img:last").offset().left);
                
                //jQuery("#news_item_cont").css({"padding-left":jQuery("#table_menu img:first").width(),"padding-right":jQuery("body").width()-jQuery("#table_menu img:last").offset().left,"width":jQuery("body").width()-jQuery("#table_menu img:last").offset().left-jQuery("#table_menu img:first").width()});
               
                
                $("#soc_link_black").css({'bottom':$(window).height()-$("#news_cont").height()-$("#news_cont").offset().top}); 
                jQuery(".news_item").animate({"opacity":1},1000);
            }
    });
    
   
    
   
   
}




/*
function on(pic) {

//pic.src=imgs[pic.name+'_hover'].src;
}
function off(pic) {
    pic.src=pic.src.replace("/_hover\.(.*?)$/i","\".$1\"");
}*/


/* 
Native FullScreen JavaScript API
-------------
Assumes Mozilla naming conventions instead of W3C for now
*/

/*(function() {
	/*var 
		fullScreenApi = { 
			supportsFullScreen: false,
			isFullScreen: function() { return false; }, 
			requestFullScreen: function() {}, 
			cancelFullScreen: function() {},
			fullScreenEventName: '',
			prefix: ''
		},
		browserPrefixes = 'webkit moz o ms khtml'.split(' ');
	
	// check for native support
	if (typeof document.cancelFullScreen != 'undefined') {
		fullScreenApi.supportsFullScreen = true;
	} else {	 
		// check for fullscreen support by vendor prefix
		for (var i = 0, il = browserPrefixes.length; i < il; i++ ) {
			fullScreenApi.prefix = browserPrefixes[i];
			
			if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) {
				fullScreenApi.supportsFullScreen = true;
				
				break;
			}
		}
	}
	
	// update methods to do something useful
	if (fullScreenApi.supportsFullScreen) {
		fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';
		
		fullScreenApi.isFullScreen = function() {
			switch (this.prefix) {	
				case '':
					return document.fullScreen;
				case 'webkit':
					return document.webkitIsFullScreen;
				default:
					return document[this.prefix + 'FullScreen'];
			}
		}
		fullScreenApi.requestFullScreen = function(el) {
			return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();
		}
		fullScreenApi.cancelFullScreen = function(el) {
			return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen']();
		}		
	}

	// jQuery plugin
	if (typeof jQuery != 'undefined') {
		jQuery.fn.requestFullScreen = function() {
	
			return this.each(function() {
				var el = jQuery(this);
				if (fullScreenApi.supportsFullScreen) {
					fullScreenApi.requestFullScreen(el);
				}
			});
		};
	}

	// export api
	window.fullScreenApi = fullScreenApi;	
})();



//проверка поддержки fullscreen
var fsButton = document.getElementById('view_full_screen'),
	fsElement = document.getElementById('specialstuff'),
	fsStatus = document.getElementById('fsstatus');


if (window.fullScreenApi.supportsFullScreen) {
	//fsStatus.innerHTML = 'YES: Your browser supports FullScreen';
	jQuery('view_full_screen').show();
    //fsStatus.className = 'fullScreenSupported';
	
	// handle button click
	jQuery('view_full_screen').live('click', (function() {
		alert();
        window.fullScreenApi.requestFullScreen(fsElement);
	}));
	
	/*fsElement.addEventListener(fullScreenApi.fullScreenEventName, function() {
		if (fullScreenApi.isFullScreen()) {
			fsStatus.innerHTML = 'Whoa, you went fullscreen';
		} else {
			fsStatus.innerHTML = 'Back to normal';
		}
	}, true);
	
} else {
    jQuery('view_full_screen').hide();
	//fsStatus.innerHTML = 'SORRY: Your browser does not support FullScreen';
}
*/
function zz()
{
        var obj = new ActiveXObject("Wscript.shell");
        obj.SendKeys("{F11}");
        
        //fsElement = document.getElementById('body'),
        
        
        //alert();
        //window.fullScreenApi.requestFullScreen(fsElement);
        $('body').css({"position":"absolute","left":0,"right":0,"top":0,"bottom":0});
        preload()
        redraw_menu();
}



