jQuery(window).bind("load", function() { 
    /*if(jQuery("#col1banners #hwgallery1").length!=0) {
        
        var gposition = jQuery("#hwgallery1").position();
        var curtop = Math.floor( gposition.top );
        curtop = curtop + 23;
        //alert(Math.floor( gposition.top ));
        jQuery('#col1banners').append('<div id="hwgallery1in" style="position:absolute; right: 1px; top:' +curtop+ 'px;height:'+jQuery("#col1banners #hwgallery1").height()+'px"></div>');
        jQuery('#hwgallery1in').css({"position":"absolute", "position":"absolute", "right":"1px", "width":"20px", "background":"url('../design/tvvideo-sh.png')", "z-index":"5"}); 
    } */
    
    if(jQuery("div#hwgallery1").length!=0) {
        jQuery("div#hwgallery1").slideView();
    }
    
    if(jQuery("div#hwgallery2").length!=0) {
        jQuery("div#hwgallery2").slideView(); 
    }
    
    if(jQuery("div#hwgallery3").length!=0) {
        jQuery("div#hwgallery3").slideView();
    }
    
    if(jQuery("div#hwgallery4").length!=0) {
        jQuery("div#hwgallery4").slideView(); 
    }
    
    if(jQuery("div#hwgallery5").length!=0) {
        jQuery("div#hwgallery5").slideView(); 
    }
	
});

jQuery(document).ready(function() {

    
    $('#topslider').nivoSlider({
            directionNav:false,
            slices:1,
            captionOpacity:0,
            effect:'sliceUp'
        });
        
        jQuery(".tlinemenu").hover(
          function () {
                jQuery("img[name="+this.name+"]").attr('src', '/design/topmarker-red.png');
          },
          function () {
            jQuery("img[name="+this.name+"]").attr('src', '/design/topmarker-gray.png');
          }
        );
        
        jQuery("#sm li").hover(
          function () {
            var t=jQuery(this).children('div').children("img");
            var src1= t.attr('src');
            var newSrc = src1.substring(0, src1.lastIndexOf('.'));
            //jQuery("#sm li").find("img").removeClass('imgact');
            //jQuery(this).children('div').children("img").toggleClass('imgact');
            //alert(t.attr('class'));
            jQuery("#sm li").find('img').each(function(){
                var src2= jQuery(this).attr('src');
                var newSrc1 = src2.substring(0, src2.lastIndexOf('.'));
                if(newSrc1.length!=14) {
                    var newSrc1 = src2.substring(0, src2.lastIndexOf('-'));
                    if(jQuery(this).attr('class')!=t.attr('class')) {
                        jQuery(this).attr('src', newSrc1 + '.' + /[^.]+$/.exec(src2));
                    }
                }
            });
            if(newSrc.length==14){
                t.attr('src', newSrc+ '-on.' + /[^.]+$/.exec(src1));
            }
          }
        );
        
        jQuery('.accontainer').hide(); //Hide/close all containers
        jQuery('.accontainer1').hide(); //Hide/close all containers
        jQuery('.accontainer2').hide(); //Hide/close all containers
        //On Click
        jQuery('.actrigger').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                var a1 = jQuery(this);
                jQuery('.actrigger').removeClass('actriggeractive').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                
                jQuery(this).toggleClass('actriggeractive').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
                //jQuery(this).css({"color": "#e83569"});
            } else {
                jQuery('.actrigger').removeClass('actriggeractive').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                //jQuery('#contentcolumnin').find('h3.actrigger').css({"color": "#ADA589"});
            }
            
            return false; //Prevent the browser jump to the link anchor
        });
        
        jQuery('.actrigger1').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                var a1 = jQuery(this);
                jQuery('.actrigger1').removeClass('actrigger1active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery('#contentcolumnin').find('h3.actrigger1').css({"color": "#ADA589"});
                
                jQuery(this).toggleClass('actrigger1active').next().slideDown(function(){
                    jQuery.scrollTo(jQuery(".addtextblock1"));    
                }); //Add "active" state to clicked trigger and slide down the immediate next container
                jQuery(this).css({"color": "#e83569"});
            } else {
                jQuery('.actrigger1').removeClass('actrigger1active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery('#contentcolumnin').find('h3.actrigger1').css({"color": "#ADA589"});
            }
            
            return false; //Prevent the browser jump to the link anchor
        });
        
        jQuery('.actrigger2').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                var a1 = jQuery(this);
                jQuery('.actrigger2').removeClass('actrigger2active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery('#contentcolumnin').find('h3.actrigger2').css({"color": "#ADA589"});
                
                jQuery(this).toggleClass('actrigger2active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
                jQuery(this).css({"color": "#e83569"});
            } else {
                jQuery('.actrigger2').removeClass('actrigger2active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery('#contentcolumnin').find('h3.actrigger2').css({"color": "#ADA589"});
            }
            
            return false; //Prevent the browser jump to the link anchor
        });
        
        jQuery('.col1submenu li span').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                jQuery('.col1submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery(this).next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
                
                //jQuery(this).css({"color":"#e83569"});
            } else {
                jQuery('.col1submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
            }
        });
        
        jQuery('.col2submenu li span').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                jQuery('.col2submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery(this).next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
            } else {
                jQuery('.col2submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
            }
        });
        
        jQuery('.col3submenu li span').click(function(){
            if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
                jQuery('.col3submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
                jQuery(this).next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
            } else {
                jQuery('.col3submenu li span').next().slideUp(); //Remove all "active" state and slide up the immediate next container
            }
        });
        
        jQuery('#apmenu span').next().css({"display":"block"});
        
        jQuery('#floginmail').focus(function(){
            if(jQuery(this).val()=="e-mail") {
                jQuery(this).val("");
            }
            
        });
        jQuery('#floginmail').blur(function(){
            if(jQuery(this).val()=="") {
                jQuery(this).val("e-mail");
            }
            
        });
        
        jQuery('#floginpass-clear').show();
        jQuery('#floginpass-real').hide();

        jQuery('#floginpass-clear').focus(function() {
            jQuery('#floginpass-clear').hide();
            jQuery('#floginpass-real').show();
            jQuery('#floginpass-real').focus();
        });
        jQuery('#floginpass-real').blur(function() {
            if(jQuery('#floginpass-real').val() == '') {
                jQuery('#floginpass-clear').show();
                jQuery('#floginpass-real').hide();
            }
        });
        
        jQuery('#fsearch').focus(function(){
            if(jQuery(this).val()=="поиск") {
                jQuery(this).val("");
            }
            
        });
        jQuery('#fsearch').blur(function(){
            if(jQuery(this).val()=="") {
                jQuery(this).val("поиск");
            }
            
        });
        
        jQuery('#fphone').focus(function(){
            if(jQuery(this).val()=="Ваш телефон") {
                jQuery(this).val("");
            }
            
        });
        jQuery('#fphone').blur(function(){
            if(jQuery(this).val()=="") {
                jQuery(this).val("Ваш телефон");
            }
            
        });
        
        jQuery('#fphone2').focus(function(){
            if(jQuery(this).val()=="Ваш телефон") {
                jQuery(this).val("");
            }
            
        });
        jQuery('#fphone2').blur(function(){
            if(jQuery(this).val()=="") {
                jQuery(this).val("Ваш телефон");
            }
            
        });
        
        jQuery('#fphoneform').submit(function(){
            var fval=jQuery('#fphone').attr('value');
            var isval = /^[0-9-+() ]{5,20}$/g.test(fval);
            if(!isval) {
                alert("Пожалуйста, введите корректный номер телефона");
                return false;
            }
        });
        
        jQuery('#fphoneform2').submit(function(){
            var fval=jQuery('#fphone2').attr('value');
            var isval = /^[0-9-+() ]{5,20}$/g.test(fval);
            if(!isval) {
                alert("Пожалуйста, введите корректный номер телефона");
                return false;
            }
        });
        
        jQuery("#phonesentok").dialog({
            height:150,
            width: 400,
            modal:true
        });
        
        jQuery("#phonesenterror").dialog({
            height:150,
            width: 400,
            modal:true
        });
        
        
        
        jQuery('.videobanner').each(function(){
            
            var minusWidth = 470 - jQuery(this).attr('width');
            jQuery(this).append('<div class="videobannerin"></div>');
            var fch = jQuery(this).children()[0];
            jQuery(fch).css({'position': 'relative'}); 
            var contPosition = jQuery(fch).position();
            jQuery(fch).append('<div class="videocontainer"></div>');
            var fch1 = jQuery(fch).children()[0];
            jQuery(fch1).css({'width' : jQuery(this).attr('width')+'px'});
            jQuery(fch1).youTubeEmbed({
                video            : 'http://www.youtube.com/watch?v='+jQuery(this).attr('rel')+'',
                width            : jQuery(this).attr('width'),
                background       : '#E4E3DE'
            });
            jQuery(fch).append('<div class="videocomment"><img src="/design/videoicon.png" style="margin-bottom:0px;padding-left:20px;"><p style="font-size: 14pt; margin-bottom:30px; color: #898778;padding-left:20px; font-weight:bold;">'+jQuery(this).attr("title")+'</p></div>');
            var fch2 = jQuery(fch).children()[1];
            jQuery(fch2).css({'position': 'absolute', 'width' : (482-jQuery(this).attr('width'))+'px', 'left': 0, 'bottom': 0});
            
            
            
            
            jQuery(fch).append('<div style="clear:both"></div>');

            
            jQuery(this).removeAttr('height');
            jQuery(this).removeAttr('width');
            jQuery(this).removeAttr('rel');
            jQuery(this).removeAttr('title');
            if(navigator.platform == "Win64") {
                jQuery(this).after('<p style="font-size:7pt;margin-top:0em;">Если у Вас возникли проблемы с просмотром видео, попробуйте установить новую версию плеера с сайта youtube.com</p>');
            }
            jQuery(this).show();
            
            
        });
        
        jQuery('.videocontainer').hover(
            function() {
                jQuery(this).children(".flashContainer").children(".controlDiv.pause").css({"background-position": "center center", "background-image":"url('../design/yt/pause.png')"});
                jQuery(this).children(".flashContainer").children(".progressBar").css({"display": "block"});
            },
            function() {
                jQuery(this).children(".flashContainer").children(".controlDiv.pause").css({"background-image":"none"});
                jQuery(this).children(".flashContainer").children(".progressBar").css({"display": "none"});
            }
        );
        
        jQuery('.videocontainer').click(function(){
            jQuery(this).children(".flashContainer").children(".controlDiv.pause").css({"background-image":"url('../design/yt/play.png')"});
            jQuery(this).children(".flashContainer").children(".controlDiv.play").css({"background-image":"url('../design/yt/play.png')"});
        });
        
        
        //alert(jQuery('#fblock31').children('div').children('p').children('iframe').attr('src'));

        jQuery('#fblock31').children('div').children('p').append('<div id="tvvideo" style="position:relative;overflow:hidden;background:rgb(0,0,0);width:269px;"></div>');
        var tvvideosrc = jQuery('#fblock31').children('div').children('p').children('iframe').attr('src');
        jQuery("#tvvideo").youTubeEmbed({
                video            : 'http://www.youtube.com/watch?v=0gbn3ADhCb0&rel=0',
                width            : 270,
                background       : '#000'
            });
        
        jQuery('#fblock31').children('div').children('p').children('iframe').remove();

        jQuery('#tvvideo').append('<div id="tvvideoin"></div>');
        //var tvheight = jQuery('#tvvideo').children('.flashContainer').children('object').attr('height');
        //alert(jQuery(tvheight));
        jQuery('#tvvideoin').css({"position":"absolute", "position":"absolute", "right":"0px", "top":"0", "width":"20px", "height": "200px", "background":"url('../design/tvvideo-sh.png')", "z-index":"5"});
        
        jQuery('#tvvideo').hover(
            function() {
                jQuery(this).children(".flashContainer").children(".controlDiv.pause").css({"background-position": "center center", "background-image":"url('../design/yt/pause.png')"});
                jQuery(this).children(".flashContainer").children(".progressBar").css({"display": "block"});
            },
            function() {
                jQuery(this).children(".flashContainer").children(".controlDiv.pause").css({"background-image":"none"});
                jQuery(this).children(".flashContainer").children(".progressBar").css({"display": "none"});
            }
        );
        
            var tn1 = jQuery('.mygallery').tn3({
            imageClick:"fullscreen",
            image:{
                maxZoom:1,
                crop:true,
                clickEvent:"dblclick",
                transitions:[{
                type:"blinds"
                },{
                type:"grid"
                },{
                type:"grid",
                duration:460,
                easing:"easeInQuad",
                gridX:1,
                gridY:8,
                // flat, diagonal, circle, random
                sort:"random",
                sortReverse:false,
                diagonalStart:"bl",
                // fade, scale
                method:"scale",
                partDuration:360,
                partEasing:"easeOutSine",
                partDirection:"left"
                }]
            },
            thumbnailer:{
                shaderOpacity: '0',
                seqLoad:false,
                shaderColor: '#ffffff',
                click: function(e) {
                    //alert(tn1.toSource());
                    if(tn1.config.isFullScreen==false) {
                        tn1.fullscreen();
                        jQuery('.tn3-fullscreen.tn3-fullscreen-active').css({"display" : "block"});
                        
                    }
                }
            
            },
            fullscreen: function(e) {
                if (e.fullscreen) {
                    jQuery('.tn3-fullscreen.tn3-fullscreen-active').css({"display" : "block"});
                }
                else {
                    jQuery('.tn3-fullscreen').css({"display" : "none"});    
                };
            }  
            }).data('tn3');
        var galobjects =  [];
        jQuery('.mygallery1').each(function(){
            var curid = jQuery(this).attr('id');
            var a1 = jQuery('#' + curid).tn3({
            imageClick:"fullscreen",
            image:{
                maxZoom:1,
                crop:true,
                clickEvent:"dblclick",
                transitions:[{
                type:"blinds"
                },{
                type:"grid"
                },{
                type:"grid",
                duration:460,
                easing:"easeInQuad",
                gridX:1,
                gridY:8,
                // flat, diagonal, circle, random
                sort:"random",
                sortReverse:false,
                diagonalStart:"bl",
                // fade, scale
                method:"scale",
                partDuration:360,
                partEasing:"easeOutSine",
                partDirection:"left"
                }]
            },
            thumbnailer:{
                shaderOpacity: '0',
                seqLoad:false,
                shaderColor: '#ffffff',
                click: function(e) {
                    //alert(tn1.toSource());
                    
                    //if(tn2.config.isFullScreen==false) {
                    //    tn2.fullscreen();
                    //    jQuery('.tn3-fullscreen.tn3-fullscreen-active').css({"display" : "block"});
                        
                    //}
                }
            
            },
            fullscreen: function(e) {
                if (e.fullscreen) {
                    jQuery('.tn3-fullscreen.tn3-fullscreen-active').css({"display" : "block"});
                }
                else {
                    jQuery('.tn3-fullscreen').css({"display" : "none"});    
                };
                
            }  
            }).data('tn3');
            galobjects.push(a1);
        });


        
        jQuery('iframe').each(function() {
            var url = jQuery(this).attr("src");
            jQuery(this).attr("src",url+"&wmode=transparent");
        });

        

});

        

//var cf = new ContentFlow('contentFlow', {reflectionHeight: 0.2, maxItemHeight: 200, circularFlow: false });
