menu_sources = Array(0,-120,-227,-335);
menu_colors = Array('#e85900','#e89d00','#1691cf','#66ad22')
accordeon_sources = Array(Array('img/header_graphic_design.png','img/header_graphic_design_hover.png'),
						  Array('img/header_web_design.png','img/header_web_design_hover.png'),
						  Array('img/header_interactive_scripting.png','img/header_interactive_scripting_hover.png'));

$(document).ready(function()  {
	change_tab (0);
	$("div#portfolio_panels > div.AccordionPanel a,div#current_work a").fancybox();
    $("#example").accordion();
	$("div.AccordionPanelTab > img").click(function (el) {
		$(document).data('curr_id', this.id.split('acc_title_')[1]);
		$("div.AccordionPanelTab > img").each(function (index,el) {
			el.src = index == ($(document).data('curr_id')) ? accordeon_sources[index][1] : accordeon_sources[index][0];
		});
	}).mouseover(function (el) {
		var index = this.id.split('acc_title_')[1];
		$(document).data('curr_id_mouse', index);
		this.src = accordeon_sources[index][1];
	}).mouseout(function (el) {
		var index = this.id.split('acc_title_')[1];
		if($(document).data('curr_id') != index) {
			this.src = accordeon_sources[$(document).data('curr_id_mouse')][0];
		}
	});
});

function change_tab (num) {
	$("div#maintxt > div").hide().filter('#main' + num).show();
	$("div#menu > ul > li").each(function (index,el) {
		var bg_pos = index == num ? '-87px' : '0px';
		var color = index == num ? '#fff' : menu_colors[index];
		$(this).css('background','url(img/menu_sprite.png) ' + menu_sources[index] + 'px ' + bg_pos + ' no-repeat');
		$(this).css('color',color);
		$(this).mouseout(function () {
			$(this).css('background','url(img/menu_sprite.png) ' + menu_sources[index] + 'px ' + bg_pos + ' no-repeat');
			$(this).css('color',color);
		});
	}); 
	setCookie('vanderwijstdesign_tab',num,365);
}

function preload(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}
function getImgWidth(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var width = newImg.width;
return width;
}

function setCookie(c_name,value,expiredays) {
	var exdate  =new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function checkCookie(cookie) {
	cookie_val = getCookie(cookie);
	if (cookie_val != null && cookie_val != "") {
		return true;
	}
	return false;
}

function change_acc (e) {
	if(e.srcElement) {
		var element = e.srcElement;
	}
	else {
		var element = this;
	}
	var item_id = element.id;
	var num = item_id.split('acc_title_')[1];
	for(i = 0; i < 3; i++) {
		$id('acc_title_' + i).src = accordeon_sources[i][0];
		if ($id('acc_title_' + i).addEventListener) {
			$id('acc_title_' + i).addEventListener ("mouseout",mouseOutAcc,false);
		} else if ($id('acc_title_' + i).attachEvent) {
			$id('acc_title_' + i).attachEvent ("onmouseout",mouseOutAcc);
		} else {
			$id('acc_title_' + i).onmouseout = mouseOutAcc;
		}
	}
	element.src = accordeon_sources[num][1];
	if (element.removeEventListener) {
		element.removeEventListener ("mouseout",mouseOutAcc,false);
	} else if (element.detachEvent) {
		element.detachEvent ("onmouseout",mouseOutAcc);
	} else {
		element.onmouseout = '';
	}
}

function $id(id) {
	return document.getElementById(id);
}

function getVar(name) { get_string = document.location.search; return_value = ''; do { name_index = get_string.indexOf(name + '='); if(name_index != -1) { get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index); end_of_value = get_string.indexOf('&'); if(end_of_value != -1) value = get_string.substr(0, end_of_value); else value = get_string; if(return_value == '' || value == '') return_value += value; else return_value += ', ' + value; } } while(name_index != -1) space = return_value.indexOf('+'); while(space != -1) { return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length); space = return_value.indexOf('+'); } return(return_value); }

function removeEvent(obj,type,fn){
  if(obj.removeEventListener) obj.removeEventListener(type,fn,false);
  else if(obj.detachEvent){
    obj.detachEvent("on"+type,obj[type+fn]);
    obj[type+fn]=null;
    obj["e"+type+fn]=null;
  }
}

window.onload = function () {
	var tooOldBrowser = jQuery.browser.msie == true && jQuery.browser.version < 7 ? true : false;
	if(tooOldBrowser == true) {
		document.body.style.background = '#000 url(img/bg_ie6.jpg) no-repeat center top';
		$id('loading').style.background = 'none';
		var loading_html = $id('loading').innerHTML;
		$id('page').style.display='none';
		$id('error').innerHTML = "<span style='font-size: 18px;'>Please update to a newer browser</span><br /><br />We are sorry, but this page is only viewable in a newer browser. We are sorry for this inconvenience.<br /><br />Click <a href=\"javascript:void(0)\" onclick=\"$id('page').style.display='block';$id('loading').style.display='none';\">here</a> to view the page (the result can be different from what you and I would expect...)";
	}
	else {
		document.getElementById('loading').style.display='none';
		load_images();
		$("#bottom_tag_img").attr('src','img/tag_bottom.png');
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function validate_contact () {
	$id('contact_form').submit();
	/*var filled = true;
	if($id('name').value == '') {
		$id('name_required').style.display = 'block';
		filled = false;
	}
	if($id('subject').value == '') {
		$id('subject_required').style.display = 'block';
		filled = false;
	}
	if($id('email').value == '' || !isValidEmail($('#email').value)) {
		$id('email_required').style.display = 'block';
		filled = false;
	}
	if($id('message').value == '') {
		$id('message_required').style.display = 'block';
		filled = false;
	}
	if(filled) $id('contact_form').submit();
	else return false;*/
}

function load_images () {
	var array1 = $id('thumbs_web_design').getElementsByTagName('a');
	for (i = 0; i < array1.length; i++) {
		preload('img/webdesign' + (i + 1) + '.jpg');
		array1[i].style.background = 'url(img/webdesign' + (i + 1) + '.jpg) no-repeat center';
	}
}

function mouseOverAcc (e) {
	if(e.srcElement) {
		var element = e.srcElement;
	}
	else {
		var element = this;
	}
	var item_id = element.id;
	var num = item_id.split('acc_title_')[1];
	element.src=accordeon_sources[num][1];
}

function mouseOutAcc (e) {
	if(e.srcElement) {
		var element = e.srcElement;
	}
	else {
		var element = this;
	}
	var item_id = element.id;
	num = item_id.split('acc_title_')[1];
	element.src=accordeon_sources[num][0];
}


// JavaScript Document
