Tag Creative

Number.prototype.map = function(istart, istop, ostart, ostop) {
  return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
};

var scroll_snap_t;

var browsers = ['msie', 'safari', 'chrome', 'mozilla'];

var snap_point_css = 'snapList(0, 768px, 1536px, 2304px, 3072px, 3840px, 4608px, 5376px, 6144px, @px, %px, $px)';
var info_can_be_clicked = true;

function checkScrollPosToElm() {
  var selected_item = $('html').attr('class').replace(/.+on_/, '');
  if (selected_item == 'people') {
    return false;
  }
  var element = $('#%'.replace('%', selected_item));
  var current_scroll_y = document.body.scrollTop;
  var elm_top_pos = $(element).offset().top;

  if (elm_top_pos != current_scroll_y) {
    $.scrollTo(element, 200, {
      onAfter: function(e) {
        clearTimeout(scroll_snap_t);
      }
    });
  }
}

$(function() {


  $(window).resize(function() {
    setPolyWidth();
  });

  $('.info').bind("click", function(e) {
    console.log('yay!', info_can_be_clicked);
    if (!info_can_be_clicked) {
      return false;
    }
    window.info_can_be_clicked = false;
    var t = setTimeout(function() {
      window.info_can_be_clicked = true;
    }, 500);
    var elm = $(e.target).parent();
    if ($(elm).is('.info_mode')) {
      if ($('html.csstransitions').size() > 0) {
        $('.info_window', elm).one('webkitTransitionEnd MSTransitionEnd transitionEnd oTransitionEnd', function(e) {
          $('.info_window', elm).css('visibility', 'hidden');
        });
      } else {
        $('.info_window', elm).css('visibility', 'hidden');
      }
      $(elm).removeClass('info_mode');

    } else {
      $('.info_window', elm).css('visibility', 'visible');
      $(elm).addClass('info_mode');
    }
  });


  $('#droid, #kexp_screens').css('display', 'block');
  for (var i = 0; i < browsers.length; i++) {
    if ($.browser[browsers[i]]) {
      var b = browsers[i];
      if (navigator.userAgent.search(/safari/gi) > -1) {
        if (navigator.userAgent.search(/chrome/gi) > -1) {
          b = 'chrome';
        }
      }
      $('html').addClass(b);
      break;
    }
  }

  var isiDevice = navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
  if (isiDevice) {
    $('html').addClass('iDevice %'.replace('%', isiDevice[0]));
  }


  function setPolyWidth() {
    var w = $(window).width();
    $('.panel').width(w);

    //var peeps_panel_pos = $('#people_panel').position();
    //var peeps_top = peeps_panel_pos.top;

    var contact_panel_pos = $('#contact_panel').position();
    var contact_snap_y = contact_panel_pos.top;
    var careers_panel_pos = $('#careers_panel').position();
    var careers_snap_y = careers_panel_pos.top;

    //var snap_points = snap_point_css.replace('@',peeps_top).replace('%',contact_snap_y).replace('$',careers_snap_y);
    //$('body').attr('style', '-ms-scroll-snap-points-y:#'.replace('#',snap_points));
  }

  $(document).bind('scroll', function(e) {
    clearTimeout(scroll_snap_t);
    scroll_snap_t = setTimeout('checkScrollPosToElm()', 2500);
  });

  $('.panel .info').bind('inview', function(e, inview) {
    if (inview) {
      var panel_name = ($(this).parent().attr('id')).replace(/_.+/gi, '');
      $('html').removeClassRegEx(/^on_.+/);
      $('html').addClass('on_%'.replace('%', panel_name));


      if (panel_name == 'home') {
        $('nav .selected').removeClass('selected');
        $('.arrow').css('opacity', '0');
        return false;
      } else {
        $('.arrow').css('opacity', '1');
      }
      var selected_nav = $('nav .%'.replace('%', panel_name));
      var pos = $(selected_nav).position();
      if ($(selected_nav).size() > 0 && pos && typeof(pos.top) == 'number') {
        $('nav .selected').removeClass('selected');
        $(selected_nav).addClass('selected');
        $('.arrow').css('top', (pos.top + 4));
      }


    }

  })

  $('.panel .share a').click(function(e) {
    var link_type = $(this).parent().attr('class');
    var fb_link = "https://www.facebook.com/dialog/feed?_path=feed&app_id=416429691721793&picture={pic}&redirect_uri=http%3A%2F%2Ftagcreativestudio.com/close.html&link={link}&picture&name={name}&caption={caption}&description={description}&from_login=1&client_id=416429691721793&display=popup";
    var link = null;
    if (link_type == 'facebook') {
      fb_link = fb_link.replace('{pic}', encodeURIComponent('http://development.tagcreativestudio.com/tagsite/images/logos/white.png'))
      fb_link = fb_link.replace('{link}', '@!'.replace('@', window.location.origin).replace('!', encodeURIComponent($(this).attr('data-section'))));
      fb_link = fb_link.replace('{name}', encodeURIComponent($(this).attr('data-name')));
      fb_link = fb_link.replace('{caption}', encodeURIComponent($(this).attr('data-caption')));
      fb_link = fb_link.replace('{description}', encodeURIComponent($(this).attr('data-description')));
      link = fb_link;
    }
    if (link_type == 'twitter') {
      link = $(this).attr('href');
    }

    if (link) {
      window.open(link, 'social', 'width=500,height=300');
    }
    e.preventDefault();
  });

  $('#people_panel .peeps li').bind('inview', function(e, inview) {
    if (inview) {
      $(e.target).addClass('inview');
    }
  })

  $("#shapes").bind('inview', function(e, inview) {
    if (inview && !$(this).hasClass('inview')) {
      $(this).addClass('inview');
    }
  })

  $('#careers_panel .careers_content_container ul').bind('inview', function(e, inview) {
    if (inview) {
      $(this).addClass('inview');
    }
  });

  setPolyWidth();
  $.each($('.panel'), function(i, elm) {
    if (!$(elm).is('#people_panel')) {

      var h = window.innerHeight;
      $(this).height(h);
      $(this).find('.bg').height(h);
      if ($(this).is('#home_panel')) {
        window.scroll(0, $(this)[0].offsetTop);
      }
    }
  })


  if (!isiDevice) {
    $(window).stellar({
      horizontalScrolling: false,
      hideElement: function($elem) {
        if ($elem[0].id != 'shapes') {
          $elem.hide();
        }
      }
    });
  }



  $('.info span, .info strong').click(function(e) {
    var elm = $(e.target).parent();
    $(elm).trigger('click');
  });


  setInterval(function() {
    imageSwitcher($('#tablet_screens img'));
    imageSwitcher($('#kexp_screens img'));
  }, 4000);

  function imageSwitcher(screen_collection) {
    var tablet_screens = $(screen_collection);
    var currently_shown_elm = $('.show', $(tablet_screens).parent());

    if ($(currently_shown_elm).length > 0) {

      $(currently_shown_elm).removeClass('show');
      var next = $(currently_shown_elm).next();
      if (next.length < 1) {
        $(tablet_screens).first().addClass('show')
      } else {
        $(next).addClass('show');
      }

    };
  }

  $('nav, #logo, .scroll').localScroll();

});
Number.prototype.map = function(istart, istop, ostart, ostop) {
	return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
};

var scroll_snap_t;

var browsers = ['msie','safari','chrome','mozilla'];

var snap_point_css = 'snapList(0, 768px, 1536px, 2304px, 3072px, 3840px, 4608px, 5376px, 6144px, @px, %px, $px)';
var info_can_be_clicked = true;

function checkScrollPosToElm(){
	var selected_item = $('html').attr('class').replace(/.+on_/,'');
	if(selected_item == 'people'){
		return false;
	}
	var element = $('#%'.replace('%', selected_item));
	var current_scroll_y = document.body.scrollTop;
	var elm_top_pos = $(element).offset().top;
	
	if(elm_top_pos != current_scroll_y){
		$.scrollTo(element, 200, {onAfter: function(e){
			clearTimeout(scroll_snap_t);			
		}});
	}
}

$(function(){
	
	
	$(window).resize(function(){
		setPolyWidth();
	});
	
	$('.info').bind("click",function(e){
		console.log('yay!', info_can_be_clicked);
		if(!info_can_be_clicked){
			return false;
		}
		window.info_can_be_clicked = false;
		var t = setTimeout(function(){
			window.info_can_be_clicked = true;
		}, 500);
		var elm = $(e.target).parent();
		if($(elm).is('.info_mode')){
			if($('html.csstransitions').size() > 0){
				$('.info_window',elm).one('webkitTransitionEnd MSTransitionEnd transitionEnd oTransitionEnd',function(e){
					$('.info_window',elm).css('visibility','hidden');
				});	
			}else{
				$('.info_window',elm).css('visibility','hidden');
			}
			$(elm).removeClass('info_mode');
			
		}else{
			$('.info_window',elm).css('visibility','visible');
			$(elm).addClass('info_mode');
		}
	});
	
	
	$('#droid, #kexp_screens').css('display','block');
	for(var i = 0; i < browsers.length; i++){
		if($.browser[browsers[i]]){
			var b = browsers[i];
			if(navigator.userAgent.search(/safari/gi) > -1){
				if(navigator.userAgent.search(/chrome/gi) > -1){
					b = 'chrome';
				}
			}
			$('html').addClass(b);
			break;
		}
	}
	
	var isiDevice = navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
	if(isiDevice){
		$('html').addClass('iDevice %'.replace('%', isiDevice[0]));
	}
	
	
	function setPolyWidth(){
		var w = $(window).width();
		$('.panel').width(w);

		//var peeps_panel_pos = $('#people_panel').position();
		//var peeps_top = peeps_panel_pos.top;
		
		var contact_panel_pos = $('#contact_panel').position();
		var contact_snap_y = contact_panel_pos.top;
		var careers_panel_pos = $('#careers_panel').position();
		var careers_snap_y = careers_panel_pos.top;
		
		//var snap_points = snap_point_css.replace('@',peeps_top).replace('%',contact_snap_y).replace('$',careers_snap_y);
		//$('body').attr('style', '-ms-scroll-snap-points-y:#'.replace('#',snap_points));
	}
	
	$(document).bind('scroll', function(e){
		clearTimeout(scroll_snap_t);
		scroll_snap_t = setTimeout('checkScrollPosToElm()', 2500);
	});
	
	$('.panel .info').bind('inview', function(e, inview){
		if(inview){
			var panel_name = ($(this).parent().attr('id')).replace(/_.+/gi,'');
			$('html').removeClassRegEx(/^on_.+/);
			$('html').addClass('on_%'.replace('%', panel_name));
			
			
			if(panel_name == 'home'){
				$('nav .selected').removeClass('selected');
				$('.arrow').css('opacity','0');
				return false;
			}else{
				$('.arrow').css('opacity','1');
			}
			var selected_nav = $('nav .%'.replace('%',panel_name));
			var pos = $(selected_nav).position();
			if($(selected_nav).size() > 0 && pos && typeof(pos.top) == 'number'){
				$('nav .selected').removeClass('selected');
				$(selected_nav).addClass('selected');
				$('.arrow').css('top',(pos.top + 4));
			}
			

		}
		
	})
	
	$('.panel .share a').click(function(e){
		var link_type = $(this).parent().attr('class');
		var fb_link = "https://www.facebook.com/dialog/feed?_path=feed&app_id=416429691721793&picture={pic}&redirect_uri=http%3A%2F%2Ftagcreativestudio.com/close.html&link={link}&picture&name={name}&caption={caption}&description={description}&from_login=1&client_id=416429691721793&display=popup";
		var link = null;
		if(link_type == 'facebook'){
			fb_link = fb_link.replace('{pic}', encodeURIComponent('http://development.tagcreativestudio.com/tagsite/images/logos/white.png'))
			fb_link = fb_link.replace('{link}','@!'.replace('@',window.location.origin).replace('!', encodeURIComponent($(this).attr('data-section'))));
			fb_link = fb_link.replace('{name}', encodeURIComponent($(this).attr('data-name')));
			fb_link = fb_link.replace('{caption}', encodeURIComponent($(this).attr('data-caption')));
			fb_link = fb_link.replace('{description}', encodeURIComponent($(this).attr('data-description')));
			link = fb_link;
		}
		if(link_type == 'twitter'){
			link = $(this).attr('href');
		}
		
		if(link){
			window.open(link, 'social', 'width=500,height=300');
		}
		e.preventDefault();
	});
	
	$('#people_panel .peeps li').bind('inview', function(e, inview){
		if(inview){
			$(e.target).addClass('inview');
		}
	})
	
	$("#shapes").bind('inview',function(e,inview){
		if(inview && !$(this).hasClass('inview')){
			$(this).addClass('inview');
		}
	})
	
	$('#careers_panel .careers_content_container ul').bind('inview', function(e, inview){
		if(inview){
			$(this).addClass('inview');
		}
	});
	
	setPolyWidth();
	$.each($('.panel'), function(i,elm){
	  if(!$(elm).is('#people_panel')){
	  
  	  var h = window.innerHeight;
  	  $(this).height(h);
  	  $(this).find('.bg').height(h);
  	  if($(this).is('#home_panel')){
  	    window.scroll(0, $(this)[0].offsetTop);
  	  }
    }
	})

	
	if(!isiDevice){
		$(window).stellar({
			horizontalScrolling: false,
			hideElement:function($elem){
				if($elem[0].id != 'shapes'){
					$elem.hide();
				}
			}
		});
	}
	

	
	$('.info span, .info strong').click(function(e){
		var elm = $(e.target).parent();
		$(elm).trigger('click');
	});
	
	
	setInterval(function(){
		imageSwitcher($('#tablet_screens img'));
		imageSwitcher($('#kexp_screens img'));
	},4000);
	
	function imageSwitcher(screen_collection){
		var tablet_screens = $(screen_collection);
		var currently_shown_elm = $('.show', $(tablet_screens).parent());

		if($(currently_shown_elm).length > 0){
			
			$(currently_shown_elm).removeClass('show');
			var next = $(currently_shown_elm).next();
			if(next.length < 1){
				$(tablet_screens).first().addClass('show')
			}else{
				$(next).addClass('show');
			}
			
		};
	}
	
	$('nav, #logo, .scroll').localScroll();

});