var browserName=navigator.appName; 
var browserCheck = "";
if (browserName=="Microsoft Internet Explorer") {
	browserCheck = "_ie";
}

var lores = 0;
var lastPage = "";

function sizeVideo () {
if (browserCheck == "_ie") {
if ($(window).height() < 770) {
$("div.content-embed").width(540).height(397);
}
else {
$("div.content-embed").width(700).height(500);
}
}
}

function nextImg (handler) {
handler = handler + "-work";
  		if ($("div#" + handler + " div.work-nav ul li.activeimg").hasClass("lastimg")) {
    		
    		$("div#" + handler + " div.contentPres").children(":visible").css("display", "none");
    		$("div#" + handler + " div.contentPres").children(":first").css("display", "block");
    		$("div#" + handler + " div.work-nav ul li.activeimg").removeClass("activeimg")
    		$("div#" + handler + " div.work-nav ul li:first").addClass("activeimg");
    	}
    	else {
    	$("div#" + handler + " div.contentPres").children(":visible").css("display", "none").next().css("display", "block");

    	$("div#" + handler + " div.work-nav ul li.activeimg").removeClass("activeimg").next().addClass("activeimg");
    	
    	}
    }


function showPage(page, section) {
	var numImgs;
	var numNavRows;
    var navPaddingTop;

	if (section == undefined) {
		section = "work";
	}
	
	if (lastPage) {
		$("#" + lastPage).css("visibility","hidden");
		if (lastPage != page + "-" + section) {
		if (section == "work") {
		if ($("div#" + page + "-" + section + " div.contentPres").html() == "") {
	$("div#" + page + "-" + section + " div.contentPres").load("work_images.php", {page: page}, function(){
		loadPageContent(page, section);

		}); 
 	} 
 	}
 	
			$("#" + page + "-" + section).css("visibility","visible");
			lastPage = page + "-" + section;
		}
		else {
			lastPage = "";
		}
		
	}
	else {
	if (section == "work") {
	if ($("div#" + page + "-" + section + " div.contentPres").html() == "") {
	$("div#" + page + "-" + section + " div.contentPres").load("work_images.php", {page: page}, function(){
		loadPageContent(page, section);

		}); 
 	}
 	}
 	
		$("#" + page + "-" + section).css("visibility","visible");
		lastPage = page + "-" + section;
	
	}
	

}

function loadPageContent(page, section) {

		
var handler = page + "-" + section;
var i = 1;
	while (i <= $("div#" + handler + " div.contentPres").children("img, div").length) {
		$("div#" + handler + " div.work-nav ul").append("<li><a href=\"#\">" + i + "</a></li>");
		i++;
	}
	$("div#" + handler + " div.work-nav ul li:last").addClass("lastimg");
		
	$("div#" + handler + " div.work-nav ul li:first").addClass("activeimg firstimg");
	
	$("div#" + handler + " div.contentPres img").css("display", "none");
	$("div#" + handler + " div.contentPres div").css("display", "none");
    $("div#" + handler + " div.contentPres").children(":first").css("display","block");
    

	$("div#" + handler + " div.work-nav ul li").click(function() {
		
		var childNo = $(this).text();
		
    
    $("div#" + handler + " div.contentPres").children(":visible").css("display", "none");
		$("div#" + handler + " div.contentPres").children(":nth-child(" + childNo + ")").css("display", "block");

    	$("div#" + handler + " div.work-nav ul li.activeimg").removeClass("activeimg");
    	$("div#" + handler + " div.work-nav ul li:nth-child(" + childNo + ")").addClass("activeimg");


	});
	$("div#" + handler + " div.work-nav ul li").mouseover(function() {
		if ($(this).attr("class") != "activeimg") {
			$(this).addClass("hoverimg");
		}
	}).mouseout(function(){
		if ($(this).attr("class") != "activeimg") {
	      	$(this).removeClass("hoverimg");
		}
    }); 
    
	$("div#" + handler + " div.contentPres img").mouseover(function() {
  		$(document).mousemove(function(e){
    		$('div.clickinfo').css("left" , e.pageX-175 + "px").css("top", e.pageY+25 + "px");
   		}); 
  		
  		
  		$("div.clickinfo").show().fadeTo("normal",1);
  		
  		
  		  		
	}).mouseout(function() {
  		$("div.clickinfo").mouseover(function() {
  		});
  		$("div.clickinfo").fadeTo(0,0).hide();  		
	});
	
	$("div#" + handler + " div.contentPres img").click(function() {

  		if ($("div#" + handler + " div.work-nav ul li.activeimg").hasClass("lastimg")) {
    		$("div#" + handler + " div.contentPres").children(":visible").css("display", "none");
    		$("div#" + handler + " div.contentPres").children(":first").css("display", "block");
    		$("div#" + handler + " div.work-nav ul li.activeimg").removeClass("activeimg")
    		$("div#" + handler + " div.work-nav ul li:first").addClass("activeimg");
    	}
    	else {
    	$("div#" + handler + " div.contentPres").children(":visible").css("display", "none").next().css("display", "block");

    	$("div#" + handler + " div.work-nav ul li.activeimg").removeClass("activeimg").next().addClass("activeimg");
    	
    	}
	});

}


function normalContent() {
$("head > style").remove();

lores = 0;
}
function loresContent() {
	$.get('css/lores_styles' +  browserCheck + '.htm',function(data){ 
		$(data).appendTo('head'); 
	}); 

lores = 1;

}

$(document).ready(function() {
		$(window).bind('resize', function () {
			if ($(window).height() < 770) {
				if (lores == 0) {
					loresContent ();
					sizeVideo();
					if (browserCheck == "_ie") {
						$("div.contentPres img").width(500);
					}
				}
			}
			else {
				if (lores == 1) {
					normalContent();
					sizeVideo();
					if (browserCheck == "_ie") {
						$("div.contentPres img").width(700);
					}
				}
			}
		});
		
		if ($(window).height() < 770) {
		loresContent ();
		sizeVideo();
		if (browserCheck == "_ie") {
			$("div.contentPres img").width(500);
		}
		
		}

	    $("object.vimeo_embed").load(function () {
	    alert(1);
	    });
});
