    function strstr( haystack, needle, bool ) {	// Find first occurrence of a string
	//
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

      var pos = 0;

      pos = haystack.indexOf( needle );
      if( pos == -1 ){
        return false;
      } else{
        if( bool ){
          return haystack.substr( 0, pos );
        } else{
          return haystack.slice( pos );
        }
      }
    }

    function setBG(which)
    {
      var w = $(window).width();
      var sub = '';
      if((w==1280 && which == '1024') || (w==1600 && which=='1200'))
      {
        sub = "_" + w;
      }
      $("#background").css("background", "url('/img/towers/"+which+sub+".png') bottom center no-repeat");
    }
    function scaleFonts(s)
    {
      var size = parseInt(s);
      size = Math.floor((size / 1024) * 100)-10;
      
      var fs = 16;
      if(size<=60)
      {
        fs=11;
      }
      else if(size>60 && size<=80)
      {
          fs=12;
      }
      else if(size>80 && size<90)
      {
        fs=14;
      } else fs=16;
      /*$("#boss").css("font-size", fs-2+"px");
      $("#boss a, #boss strong").css("font-size", fs+"px");
      $("#bossname").css("font-size", fs+"px");*/
      $("#photo_boss img").css("width", fs*9+"px");
      $("#wrapper").css("font-size", fs+"px");
      $("#ctext h1").css("font-size", fs+4+"px");
      $("#ctext p").css("font-size", fs+"px");
      $("#ctext p").css("padding", fs/10+"%");
      $("#sctext").css("font-size", fs+"px");
      var wi = $(window).width();
      
      if(wi/s>=1.25)
      {
	$(".inside #floors").removeAttr("height");
	$(".inside #floors").css("width", "99%");
      }
      if(s<=900)
      {
	 
	 $("#cafe-ftext img").css("height", "400px");
         $(".inside").css("margin", "1%");
         $(".inside").css("padding", "5px");
         $(".inside").css("width", "97%");
         $(".inside p").css("font-size", "11px");
         $(".inside h1").css("font-size", "14px");
         $("#ap_image3 img").hide();
         $("#logo img").attr("width", "80");
         $("#right").css("top", "40%");
         $("#right").css("right", "5%");
         $("#right img").attr("width", "200");
         $("#boss").css("font-size", "11px");
         $(".menuiem").css("font-size", "11px");
         $("#boss").css("width", "250px");
         $("#scimg img").attr("width", "300");
         $("#image2 img").attr("width", "250");
         $("#ap_image2 img").attr("width", "250");
         $("#ap_image1 img").attr("width", "280");
         $("#sctext").css("font-size", "12px");
         $("#sctext").css("width", "225px");
         $("#engpic img").attr("width", "150");

         $("#food img").attr("width", "250");
         $("#food div").css("margin-left", "50px");
         $("#food div").css("margin-top", "200px");
         $("#food div a").css("font-size", "14px");

         $("#fitness img").attr("width", "170");
         $("#fitness div").css("margin-left", "150px");
         $("#fitness div").css("margin-top", "140px");
         $("#fitness div a").css("font-size", "14px");

         $("#banks img").attr("width", "240");
         $("#banks div").css("margin-left", "20px");
         $("#banks div a").css("font-size", "14px");

         $("#cloth img").attr("width", "240");
         $("#cloth div").css("margin-left", "20px");
         $("#cloth div a").css("font-size", "14px");

         $("#left").css("padding", "0px 5px");
         $("#left").css("width", "25%");

      }
    }
    function changeCSS(height)
    {
      if(height>400 && height<=450)
      {
       
        setBG('425');
      }
      if(height>450 && height<=480)
      {
       
        setBG('480');
      }
      if(height>480 && height<700)
      {
       
        setBG('600');
      }
      if(height>=700 && height<800)
      {
        setBG('800');
      }
      if(height>=800 && height<900)
      {
        setBG('900');
      }
      if(height>=900 && height<1200)
      {
        setBG('1024');
      }
      if(height>=1200)
      {
        setBG('1200');
      }
      scaleFonts(height); 
    }
    $(document).ready(function(){
      var h1 = $(window).height();
      var h3 = parseInt(h1 * 1.09);
      var url = window.location.pathname.toString();
      if(strstr(url, "index") || url=="/")
      {
          changeCSS(h3);
      }
      else if(strstr(url, "contacts"))
      {
          if(h3<=1024)
          {
               $("#background").css("background", "url('/img/maps/1024.png') center center no-repeat");
          }
          else
          {
               $("#background").css("background", "url('/img/maps/1200.png') bottom center no-repeat");
          }
          scaleFonts(h3);
      }
      else
      {
        scaleFonts(h3);
      }
      $("#boss #text").hide();
      $("#bosslink").click(function(){
        $("#boss").addClass("bosstext");
        $("#boss #text").show();
        $(this).hide();
        $("#boss #close").show();
        $("#fmask").show();
        var win = $(window).width();
        var boss = $("#boss").css("width");
        var barheight = $(window).height();
        barheight*=0.75;
        barheight = Math.floor(barheight);
        $("#boss #text").scroll({width: boss, height: barheight, h1: 0});
        $("#fmask").css("width", win-parseInt(boss)+"px");
        $("#fmask").css("height", "100%");
        $("#boxtextprosc").show();
      });
      $("#close a").click(function(){
        $("#boxtextprosc").hide();
        $("#boss").removeClass("bosstext");
        $("#boss #text").hide();
        $("#close").hide();
        $("#bosslink").show();
        $("#fmask").hide();
        $(this).css("width", "0%");
        $(this).css("height", "0%");
      });
      $(".full").click(function(){
        $("#fmask").show();
        $("#fmask").css("width", "100%");
        $("#fmask").css("height", "100%");
        var el = $(this).attr("name");
        $("#"+el).show();
      });
      $("#fmask").click(function(){
        $(".inside").hide();
        $("#boxtextprosc").hide();
        $("#boss").removeClass("bosstext");
        $("#boss #text").hide();
        $("#close").hide();
        $("#bosslink").show();
        $(this).css("width", "0%");
        $(this).css("height", "0%");
        $(this).hide();
      });
      $("#larr").mouseover(function(){
          $("#larr img").attr("src", "/img/left_arr_over.png");

      });
      $("#larr").mouseout(function(){
          $("#larr img").attr("src", "/img/left_arr.png");

      });
      $("#rarr").mouseover(function(){
          $("#rarr img").attr("src", "/img/right_arr_over.png");

      });
      $("#rarr").mouseout(function(){
          $("#rarr img").attr("src", "/img/right_arr.png");

      });
    });

    $(window).bind("resize", function(){
      var h2 = $(window).height();
      var h3 = parseInt(h2 * 1.09);
      var url = window.location.toString();
      if(strstr(url, "index") || url=="/")
      {
          changeCSS(h3);
          var barheight = $(window).height();
      }
      else if(strstr(url, "contacts"))
      {
          if(h2<=1024)
          {
               $("#background").css("background", "url('/img/maps/1024.png') bottom center no-repeat");
          }
          else
          {
               $("#background").css("background", "url('/img/maps/1200.png') bottom center no-repeat");
          }
          scaleFonts(h3);
          
      }
      else
      {
          scaleFonts(h3);
      }
      document.location = document.location; /* Special for Safari */
    });
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-3484294-4']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
