
var cc = new CookieHandler();
var isopen = 0, msg_name;
var T, 
	pos, 
	gap = 130,
	myScroll,
	myScroll1,
	infoScroll;

var ipad = navigator.userAgent.match(/iPad/i);
var iphone = navigator.userAgent.match(/iPhone/i);
var ipod = navigator.userAgent.match(/iPod/i);

$(document).keyup(function(e) {
  if (e.keyCode == 27) { closepop(); };
});


$(function(){
		   		   
var headerBlock = $('#headerBlock'),
	footer = $('#footer'),
	footer_expand = $('#footer_expand'),
	main_tag = $('#mainTag'),
	uptab = $('#uptab'), item_id;;	   

	var open = false;
	$('.uptab, #upclick').click(function() {
		if(open === false) {
			$('#upclick').hide();
			$('.jScrollPaneContainer ').show();	
			$('#footerContent h1').animate({marginTop: '5px'});
			$('#filter_holder').animate({marginTop: '20px'});
			item_id = this.name;
			headerBlock.animate({marginTop: headerMarginTop+'px'});
			main_tag.animate({top: mainTagTop+'px'});
			$('#backstretch').animate({top: -(WH-bgTop)+'px'});
			if(item_id) show_info(item_id);
			$('.txt').hide();
			footer.animate({ height: (WH-headerHight)+'px' }, 300, function() {							 
				uptab.css('backgroundPosition', '0 35px');
				footer_expand.css('height', ((WH-headerHight)-scrollGap)+'px');
				footer_expand.slideDown('slow', function() {									 
					if(ipad != null || iphone != null || ipod != null){
						if(myScroll){
							myScroll.refresh();
						}else{
							setTimeout(function () { myScroll = new iScroll('footer_expand', {useTransform:false}); }, 300);
							//myScroll = new iScroll('#footer_expand');
						}
					}else{													 
						$('#footer_expand').jScrollPane({scrollbarWidth:5,showArrows:false});
					}
				});
			});
			open = true;
		} else {
			footer_expand.slideUp();								   
			headerBlock.animate({marginTop: headerTop+'px'});
			main_tag.animate({top: mainTag+'px'});
			$('#backstretch').animate({top: '0px'});
			$('#filter_holder').animate({marginTop: '60px'});
			$('#footerContent h1').animate({marginTop: '45px'});
			footer.animate({ height: '130px' });
			uptab.css('backgroundPosition', 'top left');
			$("#info").hide();
			$('#footer_info').animate({marginLeft: '0px'});
			open = false;
			
			$('.contact_msg').fadeOut();
			
			$('#upclick').show();
			$('#upclick').fadeTo('fast', 0);	
			$('.txt').show();
			$('#footer_expand').jScrollPaneRemove();
			
		}
	});
	
	$("#upclick").hover(function(){	
		if(open == false) {										 
		$('#upclick').stop().fadeTo('fast', 0.7);							 
		}
		},function(){
			if(open === false) {
				$('#upclick').stop().fadeTo('fast', 0);		
			}
	});
	
	
	
	$('.popcontent').click(function(){
		$('#pop').load('include/pop.php?id='+this.id, function() {
			$('#pop').fadeIn();
			$('#pop').height($(document).height());
			//alert($(window).height());
		});
	}); 
	
	
	$('.phead').click(function(){

		$('#pop').load('include/pop1.php?id='+this.id, function() {
			$('#pop').fadeIn();
			//$('#pop').height($(document).height());
			if(ipad != null || iphone != null || ipod != null){
				new iScroll('middle', {desktopCompatibility:true});
			}else{
				$('#scroll_news').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
	});
	
	var url=document.URL.split('#')[1];
	if(url != null){
	if(url.substring(0,4) == 'news'){
		newsID = url.replace("news=", "");
		$('#pop').load('include/pop1.php?id='+newsID, function() {
			$('#pop').fadeIn();
			//$('#pop').height($(document).height());
			if(ipad != null || iphone != null || ipod != null){
				new iScroll('middle', {desktopCompatibility:true});
			}else{
				$('#scroll_news').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
	}
	}
	
	
	
	$('.pheadall').click(function(){
		$('#pop').load('include/pop1.php', function() {
			$('#pop').fadeIn();
			//$('#pop').height($(document).height());
			if(ipad != null || iphone != null || ipod != null){
				new iScroll('middle', {desktopCompatibility:true});
			}else{
				$('#scroll_news').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
	});
	$('.st').click(function(){
		$('#pop').load('include/pop2.php?id='+this.id, function() {
			$('#pop').fadeIn();
			//$('#pop').height($(document).height());
			if(ipad != null || iphone != null || ipod != null){
				new iScroll('middle', {desktopCompatibility:true});
			}else{
				$('#scroll').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
	});
	
	$('.filter').click(function(){
								
		var id = $(this).attr('id');
		var t = $(this).attr('name');
		var col = $(this).attr('data');
		var page = $(this).attr('page');
		//var __this = $(this);

		$.post("include/filter.php", { id: id, t: t, c: col },
		function(title) {
			if(title.div == 'all'){
				$('.t_city').text('LOCATION');
				$('.t_category').text('CATEGORY');
				//$('.contact_msg').fadeOut();
			}else{
				//$("ul.filterBy a").removeClass("selected");
				//__this.parent().addClass("selected"); 
				page == 1 ? msg = title.sec1 : msg = title.sec2;
				$('.t_'+title.div).text(title.name);
				
				if(id == 0){
					//$('.contact_msg').fadeOut();
					msg_name = '';
				}else{
					//if(t == 'categories') $('.contact_msg').fadeIn().html('Due to the nature and confidentiality of these roles all opportunities are not advertised so please contact '+msg+' on 02 9267 9000 for a confidential discussion.');
					msg_name = msg;
				}
			}
			
			$(".filterBy li").find('ul:first').css({left: "500px"})
		},"json");
		
		$.post("include/f_content.php", { cid: id, t: t, c: col },
		function(data) {
			$('#holder').html(data);
				if(ipad != null || iphone != null || ipod != null){
					if(myScroll){
						myScroll.refresh();
					}else{
						myScroll = new iScroll('holder', {desktopCompatibility:true});
					}
				}else{
				$('#footer_expand').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
		
	});
	
	$(".filterBy li").hover(function(){
		if(open == true) {									 
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(200);	
			//if( ($('#footer_info').width() - $(this).width()) + $(this).find('ul:first').width() > 1020){
				$(this).find('ul:first').css({left: -($(this).find('ul:first').width()-$(this).width()+20)+"px"})
			//}else{
				//$(this).find('ul:first').css({left: "0px"})
			//}
		}
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	
	$("input.file_x1").filestyle({ 
		image: "../images/btn_browse.gif",
		imageheight : 50,
		imagewidth : 85,
		width : 130
	});
	$("input.file_x2").filestyle({ 
		image: "../images/btn_browse.gif",
		imageheight : 50,
		imagewidth : 85,
		width : 130
	});
	
	
	
	
});
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}
function LoadNewContent(id,file){
	$("#"+id+" .customScrollBox .content").load(file,function(){
		mScrollbars();
	});
}

function mScrollbars(){
	//$('#footer_expand').mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"auto","yes","yes",1); 
	$('#footer_expand').jScrollPane({scrollbarWidth:5,showArrows:false});
}

function show_info(id){
	$.post("include/getInfo.php", { id: id },
	function(data) {
		$("#info").html(data);
		$('#info_expand').css('height', ((WH-headerHight)-scrollGap)+'px');
		$('#footer_info').animate({marginLeft: '-1000px'}, 200, function() {
			$("#info").fadeIn();
			if(ipad != null || iphone != null || ipod != null){
				infoScroll = new iScroll('info_expand', {useTransform:false});
			}else{
				$('#info_expand').jScrollPane({scrollbarWidth:5,showArrows:false});
			}
		});
		//alert((WH-headerHight)-scrollGap);
	});
}

function closepop(){
	$('#pop').fadeOut();
}
function val(f,n){
	if(f.value == n) f.value = '';	
}
function fill(f,n){
	if(f.value == '') f.value = n;
}

function check_general(f){
	fo = Array(f.fname, f.lname, f.email, f.phone);
	v = Array('First name','Surname','Preferred email address','Preferred phone number');
	for(i=0; i<fo.length; i++){
		if(fo[i].value == v[i]){
			$('#fo_'+$(fo[i]).attr('id')).css('background-color', '#8E1414'); 
			return false;
		}
		$('#fo_'+$(fo[i]).attr('id')).css('background-color', '#141414'); 
	}

	em = f.email.value;
	AtPos = em.indexOf("@")
	StopPos = em.lastIndexOf(".")
	
	if (AtPos == -1 || StopPos == -1) {
		$('#fo_'+$(fo[2]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}else if (StopPos < AtPos) {
		$('#fo_'+$(fo[2]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}else if (StopPos - AtPos == 1) {
		$('#fo_'+$(fo[2]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}
	if($('#uf1').val() == ''){
		$('#fo_'+$('#uf1').attr('id')).css('background-color', '#8E1414'); 
		return false;	
	}
	$('.sbmt').hide();
	$('.load').show();
}

function CookieHandler() {

	this.setCookie = function (name, value, seconds) {
 
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}
 
		document.cookie = name+"="+value+expires+"; path=/";
		
	}
 
	this.getCookie = function (name) {
 
		name = name + "=";
		var carray = document.cookie.split(';');
 
		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
 
		return null;
	}
 
	this.deleteCookie = function (name) {
		this.setCookie(name, "", -1);
	}
 
}


