	
	var hasInnerText;
	var count = 0;
	var prevImg;
	var tag = document.createElement('script');
	var vidId;
	var player;
	var imgPath = "assets/images/";
	tag.src = "http://www.youtube.com/player_api";
	var firstScriptTag = document.getElementsByTagName('script')[0];
	var carouselCount=1;
	var cMax = 4;
	firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 
	var userType = "online";
	if(navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/1000/i) || navigator.userAgent.match(/9000/i) || navigator.userAgent.match(/m180/i) || navigator.userAgent.match(/t849/i) || navigator.userAgent.match(/i987/i) || navigator.userAgent.match(/tablet/i) || navigator.userAgent.match(/p100/i) || navigator.userAgent.match(/t849/i) || navigator.userAgent.match(/i800/i) && !viewAsMobile) {
		userType = "tablet";
	} 
	else if( navigator.userAgent.match(/(opera mini|ipod|iphone|up.browser|up.link |mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo| nokia|blackberry|pre\/0.1|android)/i) && !viewAsMobile) {
		userType = "mobile";

		location.replace("http://m.dominknow.com");	
	}
	else if (screen.width <= 699 && !viewAsMobile) {
		userType = "mobile";
		location.replace("http://m.dominknow.com");		
	}

	$(document).ready(function(){
		var p = $('#contactable').position();
		try {
			splashBanner();
			var images = document.getElementById("features").getElementsByTagName('img');
		}catch(e){}
		$('.subListItems').click(openModal);
		$('.subListItems').css({'cursor':'pointer'});
		$('#contactAt').contactable({
	 		path: contact_path,
	 		disclaimer: "Thanks for contacting us, we'll get back to you very soon"
			
	 	});
		textCarousel();
			
		}
	);


	function modalDimensions(){
		var wW = $(window).width();
		var wH = $(window).height();
		var mHeight = wH * .8;
		var mWidth = wW * .8;
		var dimensions = {
		'height': mHeight,
		'width': mWidth};
		return dimensions;
	}
	
	function modalMarg(dimensions){
	var wW = $(window).width();
	var wH = $(window).height();
	var mTop = (wH -(dimensions.height)) /2;
	var mLeft = (wW - (dimensions.width))/2;
	var margins = {
		'left': mLeft,
		'top': mTop};
	return margins;
	
	}
	function tenReasons(){
	$('#closeS').click(function(){
			$('#modal').css({'display': 'none'});
			$('#vidwindow').css({'display': 'none'});
			var elements = $('#vidwindow').children();
			$(elements[2]).remove();
		});
	$('#modal').click(function(){
			$('#modal').css({'display': 'none'});
			$('#vidwindow').css({'display': 'none'});
			$('#contactModal').animate({'left': -(315)},800);
			$('#modal').fadeOut(0);
			var elements = $('#vidwindow').children();
			$(elements[2]).remove();

			}
		);
	
		$('#modal').css({'height': '100%', 'width': '100%'});
		$('#modal').fadeIn(0);
		var modDim = modalDimensions();
		
		var imgWidth = modDim.width - (modDim.width *.1);
		var imgHeight = imgWidth *.75;
		while (imgHeight >  modDim.height - 25 - (modDim.height *.1)){
			imgWidth --;
			imgHeight = imgWidth *.75;
			if (( modDim.height - 25 - (modDim.height *.1)) > 769){
			imgHeight = 769;
			imgWidth = 769 *1.33;
			break;
			}
		}
		$('#vidwindow').css({'z-index':'9001', 'background-color': '#E5E5E5'});
			
        		
		var Img = document.createElement("img");
			Img.setAttribute('id','previewElement');
			Img.setAttribute('src','assets/images/10ReasonsFull.png');
			Img.setAttribute('alt', 'image preview');
			Img.setAttribute('height', imgHeight);
			Img.setAttribute('width', imgWidth);
			modDim.width = imgWidth + modDim.height*.2;
			$(Img).css({'position':'absolute','top': (modDim.height-imgHeight + 25)/2, 'left' : (modDim.width - imgWidth)/2});
			modDim.width = Math.ceil(imgWidth + modDim.height*.2);
			var margins = modalMarg(modDim);
			$('#vidwindow').animate({'top':margins.top,'left':margins.left, 'height':modDim.height, 'width': Math.ceil(imgWidth + modDim.height*.2)},0);
			$('#barS').css({'right':33,'width': Math.ceil($('#vidwindow').width()) - 33, 'height': 25});
			var title = document.getElementById('vidwindow').getElementsByTagName('p');
			var IText =
				(title[0].innerText != undefined) ? true : false;
			if( !IText){
			title[0].textContent = '10 Reasons to try Claro';
			}
			else{
			title[0].innerText = '10 Reasons to try Claro';
			}
			if ($('#vidwindow').children().size() != 0){
			$('#previewElement').replaceWith(Img);
			}
		$('#vidwindow').append(Img);			
		$('#vidwindow').fadeIn(300);
		
	}
	function showSixtySec(){
	$('#closeS').click(function(){
			$('#modal').css({'display': 'none'});
			$('#vidwindow').css({'display': 'none'});
			var elements = $('#vidwindow').children();
			$(elements[2]).remove();
		});
	$('#modal').click(function(){
			$('#modal').css({'display': 'none'});
			$('#vidwindow').css({'display': 'none'});
						$('#contactModal').animate({'left': -(315)},800);
			$('#modal').fadeOut(0);

			var elements = $('#vidwindow').children();
			$(elements[2]).remove();
		}
		);

		$('#modal').css({'height': '100%', 'width': '100%'});
		$('#modal').fadeIn(0);
		var modDim = modalDimensions();
		var margins = modalMarg(modDim);
		$('#vidwindow').css({'z-index':'9001', 'background-color': '#E5E5E5'});
		$('#vidwindow').animate({'top':margins.top,'left':margins.left, 'height':modDim.height, 'width': modDim.width},0);	
        $('#barS').css({'right':33,'width': $('#vidwindow').width() - 33, 'height': 25});	
		var title = document.getElementById('vidwindow').getElementsByTagName('p');
			var IText =
				(title[0].innerText != undefined) ? true : false;
			if( !IText){
			title[0].textContent = 'Claro in 60 seconds';
			}
			else{
			title[0].innerText = 'Claro in 60 seconds';
			}
		if (navigator.appName =='Microsoft Internet Explorer'){
			var vid = "http://www.youtube.com/v/9fQTqh1rgms?version=3&fs=1&rel=0&autoplay=1'";
			var h = modDim.height *.9;
			var w = modDim.width *.9
			var s = "<object id='vid' style='height:" + h + "; width:" + w +"'>" +"<embed src='"+ vid + "' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' height='" + h + "' width='" + w +"'></object>";
			var oTextNode = document.createTextNode(s);
			$('#vidwindow').append(s);
			}
		else{
		player = new YT.Player('vidwindow', {
			height: modDim.height *.9,
			width: modDim.width *.9,
			videoId: '9fQTqh1rgms',
			playerVars: {'fs':1, 'rel':0, autoplay:1}
			});
		 $('#vidwindow').append(player);	
		}
		var element = $('#vidwindow').children();
		$(element[2]).css({'margin-top': '26px', 'position' : 'absolute' ,'left' :'5%','right':'5%'});
		$('#vidwindow').fadeIn(300);
		
	}
	
	function openModal(element){
		$('#modal').click(function(){
			$('#modal').css({'display': 'none'});
			$('#modalwindow').css({'display': 'none'});
			$('#contactModal').animate({'left': -(315)},800);
			$('#preview').empty();
			$('#modal').fadeOut(0);
			}
		);
		$('#close').click(function(){
			$('#modal').css({'display': 'none'});
			$('#modalwindow').css({'display': 'none'});
			$('#contactModal').animate({'left': -(315)},800);
			$('#preview').empty();
			$('#shareModal').fadeOut(0);
			$('#modal').fadeOut(0);
		});
	
		$('#modal').css({'height': '100%', 'width': '100%'});
		$('#modal').fadeIn(0);
		
		var modDim = modalDimensions();
		var imgWidth = 769;
		var imgHeight = 447;

		
		while (imgHeight >  modDim.height - 150){
			imgWidth --;
			imgHeight = imgWidth *.57;
			if (imgHeight > 447){
			imgHeight = 447;
			imgWidth = 447 *1.73;
			break;
			}
		}
		
		$('#preview').css({'width': imgWidth, 'height':imgHeight});
		$('#view').css({'width': imgWidth + 75 });
		modDim.width = imgWidth +300;
		modDim.height = imgHeight +150;
		var margins = modalMarg(modDim);
		
		$('#modalwindow').css({'z-index':'9001', 'background-color': '#FFFFFF'});
		$('#modalwindow').css({'top':margins.top,'left':margins.left, 'height':modDim.height, 'width': modDim.width});
		$('#bar').css({'right':33,'width': $('#modalwindow').width() - 33, 'height': 25});
		$('#modalwindow').fadeIn(300);
		
	
		  var imgs = document.getElementById('features').getElementsByTagName('img');
		  var ps = document.getElementById('features').getElementsByTagName('p');
		  var title = document.getElementById('features').getElementsByTagName('h3');
		  if ($('#gallery').children().size() == 0){	  
			 for(var i = 0; i < imgs.length; i++){
				var p;
				var t;
				hasInnerText =
				(ps[i].innerText != undefined) ? true : false;
				if(!hasInnerText){
				p = ps[i].textContent;
				t = title[i].textContent;
				} 
				else{
					p = ps[i].innerText;
				    t = title[i].innerText;
					}
				
				var path = imgPath + "small/" + imgs[i].getAttribute('fname');
				var vid  = "";
				if(imgs[i].getAttribute('video') != undefined){
				 vid = imgs[i].getAttribute('video');
				}
				$('#gallery').append("<div class='horizontalmove-item'><img id ='" +imgs[i].getAttribute('id')+  "' src='"+path +
									"' fname ='" + imgs[i].getAttribute('fname') + 
									"' video= '" + vid + "' " +
									"' alt = '" + imgs[i].getAttribute('alt') +"'><h3 style='text-align: center'>"+
									t + "</h3></div>");	
			  }
			  $('.horizontalmove-item').click(function(element){
				var e = document.getElementById('preview').firstChild;
				$(e).remove();
				populateModal(element);
			 }
			 );
			  $('.horizontalmove-item').css({'cursor':'pointer'});
		  }
			populateModal(element);
	}
	
	function populateModal(element){
		var items = document.getElementById('gallery').getElementsByTagName('img');
		
		if(prevImg != undefined){
			prevImg.parentNode.className = 'horizontalmove-item';
		}
		
		for (var j=0; j < items.length; j++)
		{
			var check = element.currentTarget.getElementsByTagName('img')[0].getAttribute('fname');
			if (check == items[j].getAttribute('fname')){
				items[j].parentNode.className = 'horizontalmove-item-select';
				prevImg = items[j];
				break;
			}
		}
		
		
	    var ps = document.getElementById('features').getElementsByTagName('p');
		var tT = document.getElementById('view').getElementsByTagName('h3');
		var eT;
		var eP;
		var tP = document.getElementById('view').getElementsByTagName('p');
		var eImg =element.currentTarget.getElementsByTagName('img');
		var title = document.getElementById('features').getElementsByTagName('h3');
		var imgs = document.getElementById('features').getElementsByTagName('img');
		for(var i=0; i< title.length; i++){
			if(eImg[0].getAttribute('fname') == imgs[i].getAttribute('fname')){
				if(!hasInnerText){
				eP = ps[i].textContent;
				eT= title[i].textContent;
				} 
				else{
					eP = ps[i].innerText;
					eT= title[i].innerText;
					}
				
			}
		}


		tT[0].innerHTML = eT;
		tP[0].innerHTML = eP;

		if (eImg[0].getAttribute('video') == 'video'){
			
			if (eImg[0].getAttribute('id') == 'ppt'){
			vidId = '88NCYBMqVnU';}
			else if(eImg[0].getAttribute('id') == 'mLib'){
			vidId = 'Uhgyg7FBuzI';}
			else{
			vidId = '9fQTqh1rgms'}
			$('#gallery-pause').fadeIn(0);
			if (navigator.appName =='Microsoft Internet Explorer'){
			var vid = "http://www.youtube.com/v/" + vidId + "?version=3&fs=1&rel=0&autoplay=1'";
			var h = $('#preview').height() *.9;
			var w = +$('#preview').width() *.9;
			var s = "<object id='vid' style='height:" + h + "; width:" + w +"'>" +"<embed src='"+ vid + "' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' height='" + h + "' width='" + w +"'></object>";
			var oTextNode = document.createTextNode(s);
			$('#preview').html(s);
			}
			else{
				player = new YT.Player('preview', {
				height: $('#preview').height() *.9,
				width: $('#preview').width() *.9,
				videoId: vidId,
				playerVars: {'fs':1, 'rel':0, autoplay:1},
				events: {
					'onReady': onPlayerReady
					}
				});
				
				element = document.getElementById('preview').firstChild;
				
				$(element).css({'margin-top':$('#preview').height() * .1, 'position' : 'absolute'});
				  }
			}
		else {
			var path = imgPath + "fullsize/" + eImg[0].getAttribute('fname');
			var oImg = document.createElement("img");
			oImg.setAttribute('id','previewElement');
			oImg.setAttribute('src',path);
			oImg.setAttribute('alt', 'image preview');
			oImg.setAttribute('height', '100%');
			oImg.setAttribute('width', '100%');
			if ($('#preview').children().size() != 0){
			var element = document.getElementById('preview').firstChild;
			$(element).replaceWith(oImg);
			}
			else{
			$('#preview').append(oImg);
			}

		}
	}

	

	function onPlayerReady() {
		$('#gallery-pause').fadeOut(0);
	}
		
	function textCarousel(){
	if (carouselCount ==cMax+1){
		carouselCount = 1;
	}
	var lastCC;
	var el = document.getElementById(carouselCount);
	if (carouselCount ==1)
	{
		lastCC = cMax;
	}
	else{
	lastCC = carouselCount - 1;
	}
	var lastel = document.getElementById(lastCC);
	$(lastel).fadeOut(500);
	$(el).fadeIn(1500);
	carouselCount++;
	setTimeout("textCarousel()",13000);
	
}
