/**
  Browser Checker - isIE()
*/
function isIE() {
	if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1) { return true; }
	else { return false; }
}

/**
  Basic Toggle Div - toggle()
  
  @requires
  isIE()
  
  @arguments
  id - the id of the DOM object you wish to toggle
*/
function toggle(id) {
	var e = document.getElementById(id);
	var d = "block";
	if (!isIE()) {
		if (e.insertRow) { d = "table"; }
		else if (e.insertCell) { d = "table-row"; }
	}
	if (e.style.display == "none" || e.style.display == "") { e.style.display = d; }
	else { e.style.display = "none"; }
	return;
}

/**
  Clears input fields of default values. - clearField()
  Usage Example: <input type="text" name="name_from" value="Name" onfocus="clearField(this,'Name')" onblur="fillField(this,'Name')" />
  
  @requires
  none
  
  @arguments
  field - the DOM object whose value you wish to clear (will almost always be the self-reference of this)
  text - the default text of the field
*/
function clearField(field, text) {
	if (field.value == text) { field.value = ""; }
	return;
}

/**
  Fills input fields with default value if blank.
  
  @requires
  isblank()
  
  @arguments
  field - the DOM object whose value you wish to fill (will almost always be the self-reference of this)
  text - the default text of the field
*/
function fillField(field, text) {
	if (isblank(field.value)) { field.value = text; }
	return;
}

// Finds if a string is blank (nothing but spaces)
function isblank(x) {
	var blank = true;
	for (i = 0; i < x.length; i    ) {
		if (x.charAt(i) != ' ') { blank = false; }
	}
	return blank;
}

// Finds if a form value is empty
function isempty(x) {
	if (x == "" || isblank(x)) { return true; }
	else { return false; }
}

// Finds if a select box has not been changed
function unchanged(x) {
	if (x.selectedIndex == 0) { return true; }	
	else { return false; }
}


/* Congradulations! */

$(function() {
    var konami = "38,38,40,40,37,39,37,39,66,65".split(','); // konami keys sequence
    var keyIndex = 0;

    /* hook event function that captures keypresses made by user */
    $(document).keydown(function(ev) {
        // increase keyindex if current index matches current position in konami sequence
        (konami[keyIndex] == ev.keyCode) ? keyIndex++ : keyIndex = 0;
        if (keyIndex == konami.length) {
            window.location = "/konami.php";
            keyIndex = 0;
        }
    });
});


// Homepage Start

$(document).ready(function()
{
	// hides all DIVs with the CLASS container
	// and displays the one with the ID 'home' only
	$(".container").css("display","none");
	$("#press-a").css("display","block");
	
	// makes the navigation work after all containers have bee hidden 
	showViaLink($("#start-site a"));
	
	// listens for any navigation keypress activity
	$(document).keypress(function(e)
	{
		switch(e.which)
		{
			case 97:	showViaKeypress("#welcome");
			break;
		}
	});
});

// shows a given element and hides all others
function showViaKeypress(element_id)
{
	$(".container").css("display","none");
	// if multiple keys are pressed rapidly this will hide all but the last pressed key's div
	$(".container").hide(1);
	$(element_id).slideDown("slow");
}

// shows proper DIV depending on link 'href'
function showViaLink(array)
{
	array.each(function(i)
	{	
		$(this).click(function()
		{
			var target = $(this).attr("href");
			$(".container").css("display","none");
			$(target).slideDown("slow");
		});
	});
}


// Portfolio caption animation
	$(document).ready(function(){
		$('.portfolio-box.portfolio-caption-full').hover(function(){
			$(".cover", this).stop().animate({top:'75px'},{queue:false,duration:256});
		}, function() {
			$(".cover", this).stop().animate({top:'100px'},{queue:false,duration:256});
		});
	});

// Image zoom function
(function($){
	var initLayout = function() {
		$('a.portfolio-image').zoomimage({
			border: 20,
			centered: true,
			hideSource: true
		});
	};
	
	EYE.register(initLayout, 'init');
})(jQuery)
