// check for iphone client
function checkForIphone(){

	var browser = new Object();
	browser.str = navigator.userAgent.toUpperCase();

	if (browser.str.indexOf("IPHONE") >= 0) {

		browser.os.name = "iPhone";

		if (browser.str.indexOf("IPHONE OS ") >=0 ) {

			browser.os.ver = browser.str.match(/IPHONE OS [0-9_.]*/).toString().substr(10, 3).replace(/_/g, ".");
			return true;
		}

	}
	return false;

}

// resize window
function js_SetdivHeight() {			

	// onresize hide scrollbar
	jQuery("html").css("overflow", "hidden");
	
	var divTop, windowHeight, divHeight;
	
	divTop = jQuery("#mainContent").offset().top
	windowHeight = jQuery(window).height();
	divHeight = ((windowHeight - divTop) - 30) + "px";
	
	jQuery("#mainContent").css({"height":divHeight, "overflow":"auto"});

} 

// on window load set accordion in position
jQuery(document).ready(function() {
	

	
	jQuery('#portfolioacc').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	
	jQuery('#toolsacc').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});
	jQuery('#labcar').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	
	jQuery('#competences').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	
	jQuery('#about').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	
	jQuery('#clients').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	
	jQuery('#symbolism').accordion({
			header: 'div.title', 
			autoheight: false,
			<!-- animated: 'easeslide', -->
			active: false, 
			alwaysOpen: false
	});	


	goToAnchor();
	
	// swap image function init
	$.swapImage(".swapImage", true, true, "mouseenter", "mouseleave");
	
	// cufon font replacement
	//Cufon.replace('#header .line li a', {hover:true});
	//Cufon.replace('#header h2');

});

function goToAnchor(){
	
	var a;
	
	if(jQuery.getUrlVar('project')) {
		a = jQuery.getUrlVar('project');
		jQuery('div').scrollTo('#' + a , 500, { easing:'easeinout', queue:false, axis:'y' }); 
	} else if (jQuery.getUrlVar('tools')) {
		a = jQuery.getUrlVar('tools');		
		jQuery('div').scrollTo('#' + a , 500, { easing:'easeinout', queue:false, axis:'y' }); 
	} else if (jQuery.getUrlVar('competences')) {
		a = jQuery.getUrlVar('competences');		
		jQuery('div').scrollTo('#' + a , 500, { easing:'easeinout', queue:false, axis:'y' }); 
	} else if (jQuery.getUrlVar('lab')) {
		a = jQuery.getUrlVar('lab');		
		jQuery('div').scrollTo('#' + a , 500, { easing:'easeinout', queue:false, axis:'y' }); 
	}
	//var byTools = jQuery.getUrlVar('tools');
	//var byLab = jQuery.getUrlVar('lab');
	//var byCompetences = jQuery.getUrlVar('competences');

	
}


var _pos;
var _id;
var _acc;

// save current position on screen
function savePos(pos) {
	
	_pos = pos;	

	//_id = id;
	//_acc = acc;
}
function setProject() {

	$('div').scrollTo('#' + _pos , 500, { easing:'easeinout', queue:true, axis:'y' });
	
	//var difftop;
	//difftop = jQuery("#"+_acc+"Content_"+_id).offset().top;
	//alert(difftop)
}


// get variable from url
jQuery.extend({
  getUrlVars: function(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
  },
  getUrlVar: function(name){
	return $.getUrlVars()[name];
  }
});


// init screen
var iphoneuser = checkForIphone();		

if(iphoneuser == false){
	jQuery(window).load(js_SetdivHeight);
	jQuery(window).resize(js_SetdivHeight);
}

