var myScroll;

function loaded() {
    myScroll = new iScroll('about_scr_text');
}

$(document).ready(function(){
  if ( $.browser.msie ) {
$('.bg_img').css('visibility', 'hidden');
$('.bg_img').css('height', '600');


  if($(window).width()<=1400 ){
      var bg_h1 =$(window).height() / 100 * 60;
  }
  else var bg_h1 =$(window).height();

  //$('.bg_img').css('height', bg_h);

}
    $(".active_menu").parent().css('display', 'block');
    $(window).load(function(){
      
	if($(window).width()<= 1025){
	    $('.rightside_menu_item1').css({'font-size':'17px'});
	    $('a.rightside_menu_item1_act').css({'font-size':'17px'});
	    $('a.rightside_menu_item2').css({'font-size':'14px'});
	}
	    else
	{
	  $('.rightside_menu_item1').css({'font-size':'23px'});
	  $('a.rightside_menu_item1_act').css({'font-size':'23px'});
	  $('a.rightside_menu_item2').css({'font-size':'18px'});
	}    
      
        ab_c_m =$(document).height() / 100 * 8;
        //$('.centring_about').css({
        //    'margin-top': ab_c_m
        //});
        text_scr_h =$(document).height() / 100 * 45;
        $('.about_scr_text').css({
            'height': text_scr_h
        });
        $('.thank_you_wrapper, .booking_wrapper').height($(document).height());
        $('.thank_you_wrapper, .booking_wrapper').width($(document).width());
    });
    if( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i)
        )
        {
        $('.bg_img').height(300);
	$('.bg_img').fadeIn(1500);
    }
    else{
        if ( $.browser.msie ) {
	  if($(window).width()<=1400){
	      bg_h =$('.rightside').height() / 100 * 60;
	      $('.bg_img').height(bg_h);
	    // $('.cont_title')
	  }
	  else{
	      bg_h =$('.rightside').height();
	      $('.bg_img').height(bg_h);
	  }
	} else {
	  if($(window).width()<=1400){
	      bg_h =$(document).height() / 100 * 60;
	      $('.bg_img').height(bg_h);
	    // $('.cont_title')
	  }
	  else{
	      bg_h =$(document).height();
	      $('.bg_img').height(bg_h);
	  }
	}
    }
    
    /*
    if($(window).height()< 601){
        $('.footer, .leftside, .left_left, .vert_menu1, .vert_menu2, .vert_menu3, .vert_menu4, .rightside').height(600);
    }else{
        $('.footer, .leftside, .left_left, .vert_menu1, .vert_menu2, .vert_menu3, .vert_menu4, .rightside').height($(window).height());
    }
    */
    if($(window).width()<=1100){
        $('.rightside_menu').css({
            'margin-left': '0px'
        });
    }
    if($(window).width()>1100){
        rs_m =$(document).width() / 100 * 5;
        $('.rightside_menu').css({
            'margin-left': rs_m
        });
    }
    if($(window).width()<=1400){
        $('.cont_title').css({
            'font-size':'56px'
        });
        $('.overname').css({
            'font-size':'15px'
        });
    }
    else{
        $('.cont_title').css({
            'font-size':'95px'
        });
        $('.overname').css({
            'font-size':'25px'
        });
    }
    $(window).resize(function(){
        if( navigator.userAgent.match(/Android/i) ||
            navigator.userAgent.match(/webOS/i) ||
            navigator.userAgent.match(/iPhone/i) ||
            navigator.userAgent.match(/iPad/i) ||
            navigator.userAgent.match(/iPod/i)
            )
            {
            $('.bg_img').height(300);
        }
        else{
	    if ( $.browser.msie ) {
	      if($(window).width()<=1400){
		  var bg_h =$('.rightside').height() / 100 * 60;
		  $('.bg_img').height(bg_h);
	      }
	      else{
		  var bg_h =$('.rightside').height();
		  $('.bg_img').height(bg_h);
	      }
	    } else {
	      if($(window).width()<=1400){
		  var bg_h =$(document).height() / 100 * 60;
		  $('.bg_img').height(bg_h);
	      }
	      else{
		  var bg_h =$(document).height();
		  $('.bg_img').height(bg_h);
	      }
	    }
        }
        
        
	if($(window).width()<= 1025){
	    $('.rightside_menu_item1').css({'font-size':'17px'});
	    $('a.rightside_menu_item1_act').css({'font-size':'17px'});
	    $('a.rightside_menu_item2').css({'font-size':'14px'});
	}
	    else
	{
	  $('.rightside_menu_item1').css({'font-size':'23px'});
	  $('a.rightside_menu_item1_act').css({'font-size':'23px'});
	  $('a.rightside_menu_item2').css({'font-size':'18px'});
	}    
        
        /*
        if($(window).height()< 601){
            $('.footer, .leftside, .left_left, .vert_menu1, .vert_menu2, .vert_menu3, .vert_menu4, .rightside').height(600);
        }else{
            $('.footer, .leftside, .left_left, .vert_menu1, .vert_menu2, .vert_menu3, .vert_menu4, .rightside').height($(window).height());
        }*/
        if($(window).width()<=1400){
            $('.cont_title').css({
                'font-size':'56px'
            });
            $('.overname').css({
                'font-size':'15px'
            });
        }
        else{
            $('.cont_title').css({
                'font-size':'95px'
            });
            $('.overname').css({
                'font-size':'25px'
            });
        }
        $('.thank_you_wrapper, .booking_wrapper').height($(document).height());
        $('.thank_you_wrapper, .booking_wrapper').width($(document).width());
        text_scr_h =$(document).height() / 100 * 45;
        $('.about_scr_text').css({
            'height': text_scr_h
        });
        ab_c_m =$(document).height() / 100 * 8;
        //$('.centring_about').css({
        //    'margin-top': ab_c_m, 
        //    'padding-bottom': '26px'
        //});
        rs_m =$(document).width() / 100 * 5;
        $('.rightside_menu').css({
            'margin-left': rs_m
        });
        if($(window).width()<=1100){
            $('.rightside_menu').css({
                'margin-left': '0px'
            });
        }
        if($(window).width()>1100){
            rs_m =$(document).width() / 100 * 5;
            $('.rightside_menu').css({
                'margin-left': rs_m
            });
        }
    });
    
    $('.left_left').fadeIn(1500);
    $('.vert_menu1').delay(1000).fadeIn(500);
    $('.vert_menu2').delay(1100).fadeIn(500);
    $('.vert_menu3').delay(1200).fadeIn(500);
    $('.vert_menu4').delay(1300).fadeIn(500);
    $('.elements_title_small_contact').delay(1000).animate({
        'width':'245px'
    },1000);
    if( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i)
        )
        {
	$('.rightside').delay(1800).fadeIn(1800, function () {
	  document.getElementById('about_scr_text').addEventListener('touchmove', function (e) {
            e.preventDefault();
	  }, false);
	  loaded();
	});
        $('#slider_normal').hide(0);
        $('.shadow_on_text').hide(0);
    }
    else{
        if ($.browser.msie) {
	      
            $('.rightside').delay(1800).show(2, function(){ 
	        if($(window).width()<=1400 ){
		    var bg_h1 =$('.rightside').height() / 100 * 60;
		  }
		  else var bg_h1 =$('.rightside').height();
	      $('.bg_img').animate({height:bg_h1}, 1 ,function(){$(this).css('visibility', 'visible')})});
        }else{
            $('.rightside').delay(1800).fadeIn(1800);
	    $('.bg_img').delay(1800).fadeIn(1800);
        }
    }
    //battons
  if( !(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)) )
    $('.menu_item').hover(
        function(){
            if ($.browser.msie) {
                $(this).find('.white_menu').hide(0);
                $(this).find('.hover_menu').show(0);
            }else{
                $(this).find('.white_menu').fadeOut(500);
                $(this).find('.hover_menu').fadeIn(500);
            }
        },
        function(){
            if ($.browser.msie) {
                $(this).find('.white_menu').show(0);
                $(this).find('.hover_menu').hide(0);
            }else{
                $(this).find('.white_menu').fadeIn(500);
                $(this).find('.hover_menu').fadeOut(500);
            }
        });
    if( !(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)) )
    $('.vert_menu_item').hover(
        function(){
            if ($.browser.msie) {
                $(this).find('.white_vert').hide(0);
                $(this).find('.hover_vert').show(0);
            }else{
                $(this).find('.white_vert').fadeOut(500);
                $(this).find('.hover_vert').fadeIn(500);
            }
        },
        function(){
            if ($.browser.msie) {
                $(this).find('.white_vert').show(0);
                $(this).find('.hover_vert').hide(0);
            }else{
                $(this).find('.white_vert').fadeIn(500);
                $(this).find('.hover_vert').fadeOut(500);
            }
        });
    //footer slide
    $('.arr_up').click(function(){
        $('.bottom_footer_under').slideDown(1000);
        $(this).hide(0);
        $('.arr_down').show(0);
    });
    $('.arr_down').click(function(){
        $('.bottom_footer_under').slideUp(1000);
        $(this).hide(0);
        $('.arr_up').show(0);
    });
    <!--scroll-->
    if( !( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i)
        ) )
       /* {
        var myScroll;
        function loaded() {
            myScroll = new iScroll('about_scr_text');
        }
        document.getElementById('about_scr_text').addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);
        document.getElementById('about_scr_text').addEventListener('DOMContentLoaded', setTimeout(function () {
            loaded();
        }, 200), false);
    }
    else */
    {
	
	
	  var scroll_bar = $('#slider');
	  var scroll_content = $('#slider_wraper');
	  
	  //if(scroll_bar.height() > scroll_content.height()){
	  var slide_handler = function(e, ui) {
	      if (scroll_content.height() > scroll_content.parent().height()) {
		
		  block_height = scroll_content.height() - text_scr_h + 50;
		  block_top = Math.round( (100 - ui.value) / 100 * block_height) * (-1);
		  scroll_content.css('top',block_top + 'px');
	      } else {
		  scroll_content.css('top', 0);
		  scroll_bar.hide(0);
	      }
	  };
	  var scroll_slide = $('#slider').slider({
	      orientation: "vertical",
	      value: 100,
	      slide:slide_handler,
	      change: slide_handler
	  });
	  $('#slider, #slider_wraper').mousewheel(function(event, delta) {
	      var value = scroll_slide.slider('option', 'value');
	      if (delta > 0) {
		  value += 10;
	      }
	      else if (delta < 0) {
		  value -= 10;
	      }
	      // Ensure that its limited between 0 and 100
	      value = Math.max(0, Math.min(100, value));
	      scroll_slide.slider('option', 'value', value);
	      event.preventDefault();
	  });
	//} else {
	//  $('#slider').css('display', 'none');
	//}
    }
    //animate color
    $('.rightside_menu_item1, .rightside_menu_item2').hover(
        function () {
            $(this).animate({
                'color':'#4c4a55'
            },500);
        },
        function(){
            $(this).animate({
                'color':'#ffffff'
            },500);
        });
    //social pop-up
    $('.soc_menu_a').hover(
        function () {
            $('.social_popup').slideDown(500);
        }
        );
    $('.social_popup').hover(
        function () {
        },
        function () {
            $('.social_popup').slideUp(500);
        }
        );
    //share form pop-up
    $('.mailshare').click(function(){
        $('.social_popup').slideUp(500);
        $('.share_form').delay(500).slideDown(500);
    });
    $('.share_close_a').click(function(){
        $('.share_form').slideUp(500);
    });
    //thank you pop-up
    $('.thank_you_close_a').click(function(){
        if ($.browser.msie) {
            $('.thank_you_wrapper').slideUp(500);
        }else{
            $('.thank_you_wrapper').fadeOut(500);
        }
        return false;
    });
    $('.share_submit').click(function(){
        if ($.browser.msie) {
            $('.share_form').slideUp(500);
            $('.thank_you_wrapper').delay(500).slideDown(500);
            setTimeout("$('.thank_you_wrapper').slideUp(500)", 3000);
        }else{
            $('.share_form').slideUp(500);
            $('.thank_you_wrapper').delay(500).fadeIn(500);
            setTimeout("$('.thank_you_wrapper').fadeOut(500)", 3000);
        }
    });
    //booking pop-up
    $('#openbooking').click(function(){
        if ($.browser.msie) {
            $('.booking_wrapper').show(0);
            $('.booking_popup').show(0);
            $('.thank_popup1').hide(0);
        }else{
            $('.booking_wrapper').fadeIn(500);
            $('.booking_popup').show(0);
            $('.thank_popup1').hide(0);
        }
    });
    $('.booking_close_a').click(function(){
        if ($.browser.msie) {
	  
            $('.booking_wrapper').hide(0);
	    $("#book_an_appointment").attr('src', '/blank_frame.php');
        }else{
            $('.booking_wrapper').fadeOut(500, function(){ $("#book_an_appointment").attr('src', '/blank_frame.php'); });
            
        }
        return false;
    });
    $('.thank_you_close_a1').click(function(){
        if ($.browser.msie) {
            $('.booking_wrapper').hide(0);
        }else{
            $('.booking_wrapper').fadeOut(500);
        }
        return false;
    });
    $('.booking_submit').click(function(){
        if ($.browser.msie) {
            $('.booking_popup').hide(0);
            $('.thank_popup1').show(0);
            setTimeout("$('.booking_wrapper').hide(0)", 2000);
        }else{
            $('.booking_popup').fadeOut(500);
            $('.thank_popup1').delay(500).fadeIn(500);
            setTimeout("$('.booking_wrapper').fadeOut(500)", 3000);
        }
    });
    //shadow on text (main background)
    if($(window).width()<1000){
        $('.shadow_on_text').css({
            'left':'-60px'
        });
    }
    if($(window).width()>1000){
        $('.shadow_on_text').css({
            'left':'0px'
        });
    }
    //social networks
    function getWindowFeatures(tp_width, tp_height){
        tp_left = parseInt((screen.availWidth/2) - (tp_width/2));
        tp_top = parseInt((screen.availHeight/2) - (tp_height/2));
        return "width=" + tp_width + ",height=" + tp_height + ",status,resizable,left=" + tp_left + ",top=" + tp_top + "screenX=" + tp_left + ",screenY=" + tp_top;
    }
    $('.face').click(function(){
        window.open('http://www.facebook.com/','sharer',getWindowFeatures(620,520));
        return false;
    });
    $('.twitter').click(function(){
        window.open('http://twitter.com/intent/session?return_to=%2Fintent%2Ftweet%3Ftext%3DFACE%2Bcosmetic%2Bsurgery%26url%3Dhttp%253A%252F%252Ffacetoronto.com%252Finjectable.html','sharer',getWindowFeatures(620,520));
        return false;
    });
    $('.linkedin').click(function(){
        window.open('http://www.linkedin.com/','sharer',getWindowFeatures(620,520));
        return false;
    });
    //submenu
    $('.non_active_button_sub').click(function(){
        if($(this).next().next().css('display') == 'block') $(this).next().next().slideUp(500);
        else {
            $('.submenu').slideUp(500);
            $(this).next().next().slideDown(500);
        }
        
        setTimeout("$('.footer, .leftside, .left_left, .vert_menu1, .vert_menu2, .vert_menu3, .vert_menu4, .rightside').css({'height': $(document).height()})",500)
        return false;
    });
    //dropdown
    $('.shopping_inp_ar, .shopping_inp1').click(function(){
        $(this).next('.shopping_inp_p').slideToggle(500);
        //$(this).next('.shopping_inp_p').slideDown(500);
        return false;
    });
    $('.shopping_inp_p_a').click(function(){
        text = $(this).text();
        $(this).parent().parent().find('.shopping_inp1').val(text);
        $('.shopping_inp_p').slideUp(500);
        return false;
    });
    $('.shopping_inp_p').hover(
        function(){
        },
        function(){
            $('.shopping_inp_p').slideUp(500);
        });
    if( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i)
        )
        {
        $('.e_cl').hide(0);
        $('.e_ip').show(0);
    }else{
        $('.e_cl').show(0);
        $('.e_ip').hide(0);
    }
    //implants pop-up
    var implant_popup_timer = false;
    
    $('.non_active_button_sub_sub').click(
        function(){
            if($(this).next().next().css('display') == 'none'){
                if(implant_popup_timer) clearTimeout(implant_popup_timer);
                $('.implants_popup').slideUp(500); 
                $(this).next().next().slideDown(500); 
                implant_popup_timer = setTimeout(function(){
                    $('.implants_popup').slideUp(500);
                }, 3000);
            } else {
                $(this).next().next().slideUp(500);
                clearTimeout(implant_popup_timer);
            }    
            return false;
        }
    );
        
    $('.implants_popup').hover(
            function(){
                clearTimeout(implant_popup_timer);
            },
            function(){	
                    $('.implants_popup').slideUp(500);
    });
    
        if( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i)
        )
        {
	  setTimeout(function(){
	    $('#slider_normal').css('display', 'none');
	    $('.e_cl').css('display', 'none');
	  }, 2200);
	}
    
});
$(function(){
  setTimeout(function(){
    console.log("slider_wraper: "+ $('#slider_wraper').height() + '; slider: ' + $('#slider_wraper').parent().height());
	  if($('#slider_wraper').height() < $('#slider_wraper').parent().height()) $('#slider').css('display', 'none');
  }, 1800)
	  
});

