var snapTimer;

$(document).ready(function() {
	
	imagePath = "images/work/";
	
	//initialize intro headings
	$("#intro > h2").css({left:25, opacity:0});
	setTimeout(function(){$("#intro > h2").css({"transition-duration":"1s", "-webkit-transition-duration":"1s", "-moz-transition-duration":"1s", left:0, opacity:1});}, 500);
	
	headings = ["i'm alex", "i make websites", "i live and work in london", "i code HTML, CSS and JavaScript", "i design in photoshop, illustrator and indesign", "i use PHP and mySQL for back-end magic", "i love HTML5 and CSS3"];
	headingIndex = 0;
	setTimeout("playHeadings()", 2000);
	
	//set initial variables
	currentEntry = "hero";
	speed = 8;
	midSpeed = 4;
	topSpeed = 2;
	
	updateDimensions();
	
	if (entryHeight < 900) { $("#csmobile > .images > .image").children(".bg").remove(); $("#csmobile > .images > .image").append('<div class="bg" id="1350"></div>'); }

	$("#description").jScrollPane({scrollbarWidth:2, scrollbarOnLeft:true});
	
	//set sidebar rollovers
	$(".sidebar").hover(
		function() {
			$(".sidebar").addClass("sidebarOpen");
			$(".jScrollPaneDrag").css("opacity", 100);
		},
		function() {
			$(".sidebarOpen").removeClass("sidebarOpen");
			$(".jScrollPaneDrag").css("opacity", 0);
		}
	);
	
	if (!jQuery.browser.mobile) {
		
		//video playback
		$(".video").click(function() {
			$(this).html('<iframe src="http://player.vimeo.com/video/32735557?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>');
		});
	
		
		//setup thumbnail actions
		activateThumbnail($(".thumbnails > li > a"));
		
		//set and save offset so that images will be at the top when scrolled to
		$(".bg").css({backgroundPositionY: function(index, value) {
			var bgOffset = $(this).offset().top;
			$(this).html('<span class="' + bgOffset + '"></span>');
		}});
		$(".mid").css({backgroundPositionY: function(index, value) {
			var bgOffset = $(this).offset().top;
			$(this).html('<span class="' + bgOffset + '"></span>');
		}});
		$(".top").css({backgroundPositionY: function(index, value) {
			var bgOffset = $(this).offset().top;
			$(this).html('<span class="' + bgOffset + '"></span>');
		}});
		
		//start background scrolling
		scrolling = true;
		$(document).scroll(function() {
			scrolling = true;
		});
		bgScrolling();
		
		//set initial x positions
		panBackground(".bg", speed);
		panBackground(".mid", midSpeed);
		panBackground(".top", topSpeed);
		
		addSubImages();
	} else {
		$(".thumbnailContainer").remove();
		$(".video").remove();
		$(".bg").css("backgroundAttachment", "scroll");
		$(".mid").css("backgroundAttachment", "scroll");
		$(".top").css("backgroundAttachment", "scroll");
		$(".images").css("height", 1000);
		$(".image").children().each(function() {
			panBackground(this, 1);
		});
	}
	
	
	
});

addSubImages = function() {
	//all of a sudden
	var aoas1 = new Composition( [new Layer(imagePath+"aoas_2_1.jpg", 2000), new Layer(imagePath+"aoas_2_2.png", 574)], "#aoas", imagePath+"aoas_2_t.jpg", "" );
	var aoas2 = new Composition( [new Layer(imagePath+"aoas_3_1.jpg", 2000), new Layer(imagePath+"aoas_3_2.png", 574)], "#aoas", imagePath+"aoas_3_t.jpg", "" );
	var aoas3 = new Composition( [new Layer(imagePath+"aoas_4_1.jpg", 2000), new Layer(imagePath+"aoas_4_2.png", 574)], "#aoas", imagePath+"aoas_4_t.jpg", "" );
	var aoas4 = new Composition( [new Layer(imagePath+"aoas_5_1.jpg", 2000), new Layer(imagePath+"aoas_5_2.png", 574)], "#aoas", imagePath+"aoas_5_t.jpg", "" );
	var aoas5 = new Composition( [new Layer(imagePath+"aoas_6_1.jpg", 2000), new Layer(imagePath+"aoas_6_2.png", 574)], "#aoas", imagePath+"aoas_6_t.jpg", "" );
	
	//clearsmoke
	var isSmall = "";
	var csWidth = 2000;
	if (entryHeight < 900) { isSmall = "s"; csWidth = 1350; }
	
	var cs1 = new Composition( [new Layer(imagePath+"csmobile_2_1"+ isSmall +".jpg", csWidth)], "#csmobile", imagePath+"csmobile_2_t.jpg", "" );
	var cs1 = new Composition( [new Layer(imagePath+"csmobile_3_1"+ isSmall +".jpg", csWidth)], "#csmobile", imagePath+"csmobile_3_t.jpg", "" );
	var cs1 = new Composition( [new Layer(imagePath+"csmobile_4_1"+ isSmall +".jpg", csWidth)], "#csmobile", imagePath+"csmobile_4_t.jpg", "" );
	
	//next model
	var nm2 = new Composition( [new Layer(imagePath+"nextModel_2_1.jpg", 2000), new Layer(imagePath+"nextModel_2_2.png", 960), new Layer(imagePath+"nextModel_2_3.png", 960)], "#nextModel", imagePath+"nextModel_2_t.jpg", "" );
	var nm3 = new Composition( [new Layer(imagePath+"nextModel_2_1.jpg", 2000), new Layer(imagePath+"nextModel_3_2.png", 960), new Layer(imagePath+"nextModel_3_3.png", 960)], "#nextModel", imagePath+"nextModel_3_t.gif", "" );
	var nm4 = new Composition( [new Layer(imagePath+"nextModel_4_1.jpg", 2000), new Layer(imagePath+"nextModel_4_2.png", 526), new Layer(imagePath+"nextModel_4_3.png", 496)], "#nextModel", imagePath+"nextModel_4_t.jpg", "" );
	var nm5 = new Composition( [new Layer(imagePath+"nextModel_5_1.jpg", 2000), new Layer(imagePath+"nextModel_4_2.png", 526), new Layer(imagePath+"nextModel_5_3.png", 526)], "#nextModel", imagePath+"nextModel_5_t.jpg", "" );
	
	//dream a little dream
	var dald2 = new Composition( [new Layer(imagePath+"dald_2_1.gif", 2000), new Layer(imagePath+"dald_2_3.png", 1124)], "#dald", imagePath+"dald_2_t.gif", "" );
	var dald3 = new Composition( [new Layer(imagePath+"dald_3_1.gif", 2000), new Layer(imagePath+"dald_3_3.png", 484)], "#dald", imagePath+"dald_3_t.gif", "" );
	var dald4 = new Composition( [new Layer(imagePath+"dald_4_1.gif", 2000), new Layer(imagePath+"dald_4_3.png", 2000)], "#dald", imagePath+"dald_4_t.gif", "" );
	var dald5 = new Composition( [new Layer(imagePath+"dald_5_1.gif", 1467)], "#dald", imagePath+"dald_5_t.gif", "" );
	
	//connect
	/*var connect2 = new Composition( [new Layer(imagePath+"connect_2_1.gif", 2000), new Layer(imagePath+"connect_2_2.png", 557), new Layer(imagePath+"connect_2_3.png", 557)], "#connect", imagePath+"connect_2_t.gif", "#0c3a51" );
	var connect3 = new Composition( [new Layer(imagePath+"connect_3_1.gif", 1000), new Layer(imagePath+"connect_3_2.png", 1000), new Layer(imagePath+"connect_3_3.png", 700)], "#connect", imagePath+"connect_3_t.gif", "#f3f3f3" );
	var connect3 = new Composition( [new Layer(imagePath+"connect_4_1.gif", 1000), new Layer(imagePath+"connect_4_2.png", 1000), new Layer(imagePath+"connect_4_3.png", 1000)], "#connect", imagePath+"connect_4_t.gif", "#f3f3f3" );*/
	
	//myteam
	var myteam2 = new Composition( [new Layer(imagePath+"myteam_2_1.jpg", 2000), new Layer(imagePath+"myteam_2_2.png", 934)], "#myteam", imagePath+"myteam_2_t.gif", "" );
	var myteam3 = new Composition( [new Layer(imagePath+"myteam_3_1.jpg", 2000), new Layer(imagePath+"myteam_3_2.png", 926)], "#myteam", imagePath+"myteam_3_t.gif", "" );
	var myteam4 = new Composition( [new Layer(imagePath+"myteam_4_1.jpg", 2000), new Layer(imagePath+"myteam_4_2.png", 469)], "#myteam", imagePath+"myteam_4_t.gif", "" );
	var myteam5 = new Composition( [new Layer(imagePath+"myteam_5_1.jpg", 2000), new Layer(imagePath+"myteam_5_2.png", 940)], "#myteam", imagePath+"myteam_5_t.gif", "" );
	var myteam6 = new Composition( [new Layer(imagePath+"myteam_6_1.jpg", 2000), new Layer(imagePath+"myteam_6_2.png", 940)], "#myteam", imagePath+"myteam_6_t.gif", "" );
	var myteam6 = new Composition( [new Layer(imagePath+"myteam_7_1.jpg", 2000), new Layer(imagePath+"myteam_7_2.png", 934)], "#myteam", imagePath+"myteam_7_t.gif", "" );
	var myteam6 = new Composition( [new Layer(imagePath+"myteam_8_1.jpg", 506), new Layer(imagePath+"myteam_8_2.png", 1000)], "#myteam", imagePath+"myteam_8_t.gif", "#fff" );
	
	//eDMs
	var edm2 = new Composition( [new Layer(imagePath+"edm_2_1.jpg", 650), new Layer(imagePath+"edm_2_2.png", 650), new Layer(imagePath+"edm_2_3.png", 650)], "#edm", imagePath+"edm_2_t.jpg", "" );
	var edm3 = new Composition( [new Layer(imagePath+"edm_3_1.jpg", 700), new Layer(imagePath+"edm_3_2.png", 700), new Layer(imagePath+"edm_3_3.png", 700)], "#edm", imagePath+"edm_3_t.gif", "" );
	var edm4 = new Composition( [new Layer(imagePath+"edm_4_1.jpg", 693), new Layer(imagePath+"edm_4_2.png", 693)], "#edm", imagePath+"edm_4_t.gif", "" );
	var edm5 = new Composition( [new Layer(imagePath+"edm_5_1.jpg", 700), new Layer(imagePath+"edm_5_2.png", 150)], "#edm", imagePath+"edm_5_t.jpg", "" );
	var edm6 = new Composition( [new Layer(imagePath+"edm_6_1.jpg", 650), new Layer(imagePath+"edm_6_2.png", 650)], "#edm", imagePath+"edm_6_t.jpg", "" );
	var edm7 = new Composition( [new Layer(imagePath+"edm_7_1.jpg", 650), new Layer(imagePath+"edm_7_2.png", 650)], "#edm", imagePath+"edm_7_t.jpg", "#fff8c0" );
	var edm8 = new Composition( [new Layer(imagePath+"edm_8_1.jpg", 650), new Layer(imagePath+"edm_8_2.png", 650), new Layer(imagePath+"edm_8_3.png", 650)], "#edm", imagePath+"edm_8_t.jpg", "" );
	
	//diagrams
	var diagram2 = new Composition( [new Layer(imagePath+"diagram_2_1.gif", 923), new Layer(imagePath+"diagram_2_2.png", 923), new Layer(imagePath+"diagram_2_3.png", 923)], "#diagram", imagePath+"diagram_2_t.gif", "" );
	var diagram3 = new Composition( [new Layer(imagePath+"diagram_3_1.gif", 1000), new Layer(imagePath+"diagram_3_2.png", 1000), new Layer(imagePath+"diagram_3_3.png", 1000)], "#diagram", imagePath+"diagram_3_t.gif", "" );
	var diagram4 = new Composition( [new Layer(imagePath+"diagram_4_1.gif", 606), new Layer(imagePath+"diagram_4_2.png", 606), new Layer(imagePath+"diagram_4_3.png", 606)], "#diagram", imagePath+"diagram_4_t.gif", "" );
	var diagram5 = new Composition( [new Layer(imagePath+"diagram_5_1.gif", 900), new Layer(imagePath+"diagram_5_2.png", 900), new Layer(imagePath+"diagram_5_3.png", 900)], "#diagram", imagePath+"diagram_5_t.gif", "#e6e6e6" );
	
	//digg
	var digg2 = new Composition( [new Layer(imagePath+"digg_2.jpg", 2000)], "#digg", imagePath+"digg_2_t.jpg", "" );
	var digg3 = new Composition( [new Layer(imagePath+"digg_3.jpg", 2000)], "#digg", imagePath+"digg_3_t.jpg", "" );
	var digg4 = new Composition( [new Layer(imagePath+"digg_4.jpg", 2000)], "#digg", imagePath+"digg_4_t.jpg", "" );
}


bgScrolling = function() {
	if (scrolling) {
		clearTimeout(snapTimer);
		snapTimer = null;
		
		//only scroll the current, prev and next
		scrollBackground("#" + currentEntry + " > .images > .active > .bg", speed);
		scrollBackground("#" + currentEntry + " > .images > .active > .mid", midSpeed);
		scrollBackground("#" + currentEntry + " > .images > .active > .top", topSpeed);
		
		var nextEntry = $("#" + currentEntry).next().attr("id");
		scrollBackground("#" + nextEntry + " > .images > .active > .bg", speed);
		scrollBackground("#" + nextEntry + " > .images > .active > .mid", midSpeed);
		scrollBackground("#" + nextEntry + " > .images > .active > .top", topSpeed);
		
		var prevEntry = $("#" + currentEntry).prev().attr("id");
		scrollBackground("#" + prevEntry + " > .images > .active > .bg", speed);
		scrollBackground("#" + prevEntry + " > .images > .active > .mid", midSpeed);
		scrollBackground("#" + prevEntry + " > .images > .active > .top", topSpeed);
		
		scrolling = false;
	
		//check for scroll position to change descriptions
		$(".entry").each(function() {
			if ( Math.abs($(document).scrollTop() - $(this).offset().top) < 150 ) {
				if ( currentEntry != $(this).attr("id") ) {
					currentEntry = $(this).attr("id");
					$(".jScrollPaneContainer").remove();
					$("#sidebar").append('<div id="description">' + $("#"+currentEntry).children(".description").html() + '</div>');
					$("#description").css("height", entryHeight-340);
					$("#description").jScrollPane({scrollbarWidth:2, scrollbarOnLeft:true});
					$("#description").css({'paddingLeft':'7px', 'paddingRight':'5px', 'width':'168px'});
				}
			}
		});
	} else {
		if (!snapTimer && currentEntry != "hero" && Math.abs($(document).scrollTop()-$("#"+currentEntry).offset().top) < 100 ) {
			snapTimer = setTimeout(function() { $("html:not(:animated),body:not(:animated)").animate({scrollTop: $("#"+currentEntry).offset().top}, 100) }, 500);
		}
	}
	
	t = setTimeout("bgScrolling()",10);
}

bgPanning = function() {
	panBackground("#"+currentEntry+" > .images > .image > .bg", speed);
	panBackground("#"+currentEntry+" > .images > .image > .mid", midSpeed);
	panBackground("#"+currentEntry+" > .images > .image > .top", topSpeed);
	panningTimer = setTimeout("bgPanning()",10);
}

scrollBackground = function(element, speed) {
	$(element).css({"backgroundPosition": function(index, value) {
		var xPos = value.substr(0, value.indexOf(" "));
		
		var scrollAmount = $(document).scrollTop()/-speed + parseFloat($(this).children("span").attr("class"))/speed;
		if ( centering && $(this).hasClass("center") ) { scrollAmount -= entryHeight/2; }
		var bgPos = xPos + " " + scrollAmount + "px";
		return bgPos;
	}});
}

panBackground = function(element, speed) {
	$(element).css({"backgroundPosition": function(index, value) {
		var yPos = value.substr(value.indexOf(" ")+1, 10);
		
		var imgWidth = $(this).attr("id");
		var scrollAmount = $(this).offset().left/speed + entryWidth/2 - imgWidth/2;
		if ( $(this).hasClass("right") ) { scrollAmount -= (imgWidth - entryWidth)/2; }
		if ( $(this).hasClass("left") ) { scrollAmount += (imgWidth - entryWidth)/2; }
		var bgPos = scrollAmount + "px " + yPos;
		return bgPos;
	}});
}

playHeadings = function() {
	$("#intro > h3").css({left:-25, opacity:0});
	setTimeout(function() { $("#intro > h3:first").remove(); }, 1000);
	$("#intro").append("<h3>" + headings[headingIndex] + "</h3>");
	setTimeout(function(){$("#intro > h3:last").css({left:5, opacity:1})},10);
	headingIndex++;
	if (headingIndex >= headings.length) {headingIndex = 0;}
	setTimeout("playHeadings()", 3000); 
}

updateDimensions = function() {
	//set heights of entries
	entryHeight = $(window).height();
	$(".entry").css("height", entryHeight+50);
	$(".bg").css("height", entryHeight+50);
	$(".mid").css("height", entryHeight+50);
	$(".top").css("height", entryHeight+50);
	$("#hero").css("height", entryHeight-50);
	$(".image").css("height", entryHeight+50);
	$("#description").css("height", entryHeight-340);
	$(".jScrollPaneContainer").css("height", entryHeight-340);
	$("#description").jScrollPane({scrollbarWidth:2, scrollbarOnLeft:true});
	$("#description").css({'paddingLeft':'7px', 'paddingRight':'5px', 'width':'168px'});
	$(".video").css("marginTop", (entryHeight/2)-180);
	
	//set widths of entries
	entryWidth = $(window).width();
	$(".bg").css("width", entryWidth);
	$(".mid").css("width", entryWidth);
	$(".top").css("width", entryWidth);
	$(".image").css("width", entryWidth);
	$(".video").css("marginLeft", (entryWidth/2)-320)
	
	if ( entryHeight > 800 ) { centering = false; } else { centering = true; }
	
	//update x offsets of each comp container	
	$(".images").each(function() {
		$(this).children(".image").each(function(i) {
			if ( $(this).hasClass("active") ) {
				$(this).parent().css("left", -entryWidth*i);
			}
			$(this).css({
				"left":i*entryWidth,
				"bottom":i*entryHeight+i*50
			});
		});
	});
}

$(window).resize(function() {
	updateDimensions();
	panBackground(".bg", speed);
	panBackground(".mid", midSpeed);
	panBackground(".top", topSpeed);
});


/* ENTRY CLASSES */

function Layer(url, width) {
	this.url = url;
	this.width = width;
	this.position = "";
}

Layer.prototype.addPosition = function(newPosition) {
	this.position = newPosition;
}

//layers must be added in order - bg, mid, top
function Composition(layers, parentID, thumbnailURL, bgColour) {
	this.layers = layers;
	this.parentID = parentID;
	this.thumbnailURL = thumbnailURL;
	this.bgColour = bgColour;
	this.totalImages = this.layers.length;
	this.loadedImages = 0;
	
	//load images via AJAX
	for (var i = 0; i < this.totalImages; i++) {
		var img = new Image();
		$(img).load(this.checkProgress())
			.error(function() { alert("oh no, something has gone horribly wrong. WHAT DID YOU DO"); })
			.attr("src", this.layers[i].url);
	}
}

Composition.prototype.checkProgress = function() {	
	this.loadedImages++;
	if ( this.loadedImages >= this.totalImages ) { this.addToPage(); }
}

Composition.prototype.addToPage = function() {
	//add thumbnail
	var thumb = new Image();
	var parentID = this.parentID;
	var compImage = '<div class="image" style="background: ' + this.bgColour + '">';
	var layers = this.layers;
	$(thumb).load(function() {
		var layerNames = ["bg", "mid", "top"];
		for (var i = layers.length-1; i >= 0; i--) {
			if ( layers[i].position ) { layers[i].position = " " + layers[i].position; }
			compImage += '<div class="' + layerNames[i] + layers[i].position + '" id="' + layers[i].width + '" style="background-image: url(' + layers[i].url + ')"></div>';
		}
		compImage += '</div>';
		$(parentID).children(".images").append(compImage);
		$(parentID).children(".images").children(".image").last().children("div").css({"backgroundPosition": function(index, value) {
			var bgOffset = $(this).parent().parent().children(".image").first().offset().top;
			$(this).html('<span class="' + bgOffset + '"></span>');
		}});
		
		updateDimensions();
		
		var thumbnail = '<li class="ajax"><a href="javascript:void(0)"><img src="' + this.src + '" alt="hi" width="50" height="50" /></a></li>';
		$(parentID).children(".thumbnailContainer").children(".thumbnails").append(thumbnail);
		setTimeout('$("li.ajax").css({opacity:1, right:0})', 1);
		
		//activate thumbnail
		activateThumbnail($(parentID).children(".thumbnailContainer").children(".thumbnails").children("li:last").children("a"));
	}).error(function() { alert("thumbfail."); })
		.attr("src", this.thumbnailURL);
	
}

activateThumbnail = function(element) {
	$(element).click(function() {
		//fix scrolling
		$(document).scrollTop($(this).parent().parent().parent().parent().offset().top);
		scrolling = true;
		
		//activate and timeout the image panning
		bgPanning();
		setTimeout(function() { clearTimeout(panningTimer); },1000);
		
		//get the location of the new image
		imgNum = $(this).parent().parent().children("li").index($(this).parent());
		
		//navigate to new image
		$(this).parent().parent().parent().siblings(".images").css("left", entryWidth*-imgNum);
		currentEntry = $(this).parent().parent().parent().parent().attr("id");
		$("#"+currentEntry).children(".images").children(".active").removeClass("active");
		$("#"+currentEntry).children(".images").children(".image").eq(imgNum).addClass("active");
		
		//add/remove active class
		$(this).parent().parent().children("li").children(".active").removeClass("active");
		$(this).addClass("active");
	});
}


/* KEYBOARD SHORTCUTS */

$(document).keydown(function(e) {
	var keypressed = String.fromCharCode(e.which);
	//alert(keypressed);
	if ( keypressed == "(" ) { /* DOWN */
		e.preventDefault();
		$("html:not(:animated),body:not(:animated)").animate({scrollTop: $("#"+currentEntry).next().offset().top}, 500);
	} else if ( keypressed == "&" ) { /* UP */
		e.preventDefault();
		$("html:not(:animated),body:not(:animated)").animate({scrollTop: $("#"+currentEntry).prev().offset().top}, 500);
	} else if ( keypressed == "'" ) { /* RIGHT */
		var activeThumb = $("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").children(".active");
		imgNum = $("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").index($(activeThumb).parent())+1;
		if ( $("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").length > imgNum ) {
			//activate and timeout the image panning
			bgPanning();
			setTimeout(function() { clearTimeout(panningTimer); },1000);
			
			//navigate to the new image
			$("#"+currentEntry).children(".images").css("left", entryWidth*-imgNum);
			$("#"+currentEntry).children(".images").children(".active").removeClass("active");
			$("#"+currentEntry).children(".images").children(".image").eq(imgNum).addClass("active");
			
			//add/remove active class
			$(activeThumb).removeClass("active");
			$("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").eq(imgNum).children("a").addClass("active");
		}
	} else if ( keypressed == "%" ) { /* LEFT */
		var activeThumb = $("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").children(".active");
		imgNum = $("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").index($(activeThumb).parent())-1;
		if ( imgNum >= 0 ) {
			//activate and timeout the image panning
			bgPanning();
			setTimeout(function() { clearTimeout(panningTimer); },1000);
			
			//navigate to the new image
			$("#"+currentEntry).children(".images").css("left", entryWidth*-imgNum);
			$("#"+currentEntry).children(".images").children(".active").removeClass("active");
			$("#"+currentEntry).children(".images").children(".image").eq(imgNum).addClass("active");
			
			//add/remove active class
			$(activeThumb).removeClass("active");
			$("#"+currentEntry).children(".thumbnailContainer").children(".thumbnails").children("li").eq(imgNum).children("a").addClass("active");
		}
	}
});






//detect mobile
//jQuery.browser.mobile (http://detectmobilebrowser.com/)
(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);













