/**/
jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++)	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}
/*	dynamicCSS.js v1.0 <http://www.bobbyvandersluis.com/articles/dynamicCSS.php>
	Copyright 2005 Bobby van der Sluis
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
function createStyleRule(selector, declaration) {
	if (!document.getElementsByTagName || !(document.createElement || document.createElementNS)) return;
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_iewin = (is_ie && (agt.indexOf("win") != -1));
	var is_iemac = (is_ie && (agt.indexOf("mac") != -1));
	if (is_iemac) return; // script doesn't work properly in IE/Mac
	var head = document.getElementsByTagName("head")[0]; 
	var style = (typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", "style") : document.createElement("style");
	if (!is_iewin) {
		var styleRule = document.createTextNode(selector + " {" + declaration + "}");
		style.appendChild(styleRule); // bugs in IE/Win
	}
	style.setAttribute("type", "text/css");
	style.setAttribute("media", "screen"); 
	head.appendChild(style);
	if (is_iewin && document.styleSheets && document.styleSheets.length > 0) {
		var lastStyle = document.styleSheets[document.styleSheets.length - 1];
		if (typeof lastStyle.addRule == "object") { // bugs in IE/Mac and Safari
			lastStyle.addRule(selector, declaration);
		}
	}
}
/**/
String.prototype.toProperCase = function(){
	return this.toLowerCase().replace(/\w+/g,function(s){
		return s.charAt(0).toUpperCase() + s.substr(1);
	})
}
/* urchin */
_uacct = "UA-242552-7";
urchinTracker();
/* globalz */
req=window.location.href;
window.first=true;
if(req.indexOf('admin')!=-1)window.admin=true;
else window.admin=false;
if (window.XMLHttpRequest&&req.indexOf('php')!=-1&&!window.admin&&req.indexOf('register')==-1&&req.indexOf('cache')==-1){
	if (req.indexOf('program/')!=-1) pos=req.indexOf('/program/');
	else if (req.indexOf('partners/')!=-1) pos=req.indexOf('/partners/');
	else pos=req.lastIndexOf("/");
	window.location.replace(req.substr(0,pos)+"/#"+req.substr(pos+1,req.length).replace('.php',''));
}
jQuery.extend({
	pagetitles: { '#hotels': 'Accommodation', '#fees': 'Congress Fees', '#index': 'About', '#requirements': 'Invitation Requirements', '#all_about': 'What\'s This All About?' },
	speedz: { '#index': 1300, '#program': 2000, '#venue': 1300, '#accommodation': 1800, '#registration': 1300, '#request_invitation': 1300 }
});
if($.fn.flash.hasFlash(8)) createStyleRule("#left", "background-image:none!important;");
createStyleRule("#progress", "opacity: 0; filter: alpha(opacity=0);");
createStyleRule("#wrapper div", "display: none;");
if ($.browser.mozilla)createStyleRule("html","overflow: -moz-scrollbars-vertical;");
if (!window.admin) $.preloadImages("gfx/bg313.png");

$(window).bind("load", function(){
	connect_init();
	if (!window.admin)$.historyInit(pageload);
});
$().ready(function(){
	connect_check_white(window.location.href);
});
/* */
function ie7(){
	return typeof document.body.style.maxHeight != "undefined";
}
$(window).ajaxError(function(req,set){
	$('div.content').html('<h1>404 Error</h1>');
	connect_animate($('div.content'),'show',600);
	window.loading=false;
});
function connect_check_white(page){
	var divs = $('#wrapper,#footah');
	var white = /venue|travel|dubrovnik|accommodation|airlines/.test(page.toString()||'')
	if (white && !divs.is('.white')) divs.addClass('white');
	else if (!white && divs.is('.white')) divs.removeClass('white');
}

function connect_leftism(page){
	if ($.browser.msie) obj = window['left_flash'];
	else obj = document['left_flash'];
	if (obj&&obj.leftism) obj.leftism(page);
	else setTimeout(function(){connect_leftism(page)}, 50);
}

function connect_load_page(page,callback){
	if(typeof page == 'undefined') page='index.php';
	if (!window.loading) {
		window.loading=true;	
		connect_leftism(page);
		$('#progress').css('opacity', 0).css('filter', 'alpha(opacity=0)')
		if ($.browser.msie&&ie7()) speed = 200; else speed=500;
		$('div.content').fadeOut(speed,function(){
			connect_check_white(page);
			$.get(page, {a:1}, function(data){
					window.loading=false;
					$('div.content').html(data).removeAttr('style');//.height(0);
					if ($('div.content #kontaktform').length) connect_form();
					connect_animate($('div.content'),'show',$.speedz[$.historyCurrentHash]||1400);
					setTimeout(connect_settitle,500);
					if (typeof callback == 'function') callback();
					$('div.content a:not([@target])').not('.email').unclick().click(function(){
						if (this.hostname == location.hostname)	return connect_history_load(this.href);
					});
					connect_form();
					$('div.content a.email').attr({'href':'mailto:info@pharmacon2007.com'}).html('info@pharmacon2007.com');
			});
		});	
	}
	return false;
}
function connect_animate(div,op,speed,callback){
	if ($.browser.msie&&ie7()) {
		if (op=='show'){
			hash = {'height': 'show'};
		} else {
			hash = {'height': 'hide'};
		}
	} else {
		if (op=='show'){
			hash = {'height':'show','opacity':'show'};
		} else {
			hash = {'height':'hide','opacity':'hide'};
		}
	}
	div.animate(hash, speed, 'easeout', callback);
}
function pageload(hash) {
	if($.trim(hash).length>1) {
		if (!window.first||hash!='index') connect_load_page(hash+".php");
	} else if (!window.first) {
		connect_load_page('index.php');
	}
	window.first=false;
}
	
function connect_form(){
	connect_form_globals();
	$('#formwrap').hide();
	$('select[@name=occupation]').unchange().change(function(){
		if ($(this).val()=="-1")return;
		$('#formwrap div').hide();
		$('label[@for=message] span').html('I');
		switch($(this).val()) {
			case "0":
				$('#student').show();
				break;
			case "1":
				$('#professional').show();
				break;
			case "2":
				$('#corporate').show();
				$('#formwrap label[@for=message] span').html('We');
				break;
		}
		connect_animate($('#formwrap'),'show',600);
	});
	$('input[@name=back]').click(function(){
		return connect_history_load(window.current);
	});
	var options = {
		dataType: 'json',
		before: function(formArray, jqForm) {
			$('form *').removeClass('error');
			error = false;
			if ($.trim($('input[@name=first_name]').val())==""){
				$('input[@name=first_name]').addClass('error');
				if (!error) error = 'first_name';
			}
			if ($.trim($('input[@name=last_name]').val())==""){
				$('input[@name=last_name]').addClass('error');
				if (!error) error = 'last_name';
			}
			switch($('select[@name=occupation]').val()) {
				case "0":
					if ($('select[@name=status]').val()=="-1") {
						$('select[@name=status]').addClass('error');
						if (!error) error = 'status';
					}
					break;
				case "1":
					if ($.trim($('input[@name=job]').val())==""){
						$('input[@name=job]').addClass('error');
						if (!error) error = 'job';
					}
					break;
				case "2":
					if ($.trim($('input[@name=company]').val())==""){
						$('input[@name=company]').addClass('error');
						if (!error) error = 'company';
					}
					break;
			}
			if ($.trim($('input[@name=email]').val())==""||!connect_check_email($('input[@name*=email]').val())) {
				$('input[@name*=email]').addClass('error');
				if (!error) error = 'email';
			}
			if ($.trim($('select[@name=country]').val())=="-1"){
				$('select[@name=country]').addClass('error');
				if (!error) error = 'country';
			}
			if ($.trim($('textarea').val())==""){
				$('textarea').addClass('error');
				if (!error) error = 'message';
			}
			if (error != '') {
				$('form *[@name='+error+']')[0].focus();
				connect_progress('Please fill in all required fields..');
				return false;
			} else {
				connect_progress('Sending..');
			}
		},
		after: function(res){
			$('form *[@name]').removeClass('error');
			if (res.status == 'ok') {
				$('input[@type=text],textarea').val('');
				$('select').val("-1");
				$('#formwrap').hide();
			}	else 	if (res.error == 'send') {
				connect_progress(res.html);	
			} else {
				$.each(res.error, function(i,n){ 
					$('form *[@name='+n+']').addClass('error');
					if (i==0)$('form *[@name='+n+']')[0].focus();
				});
			}
			connect_progress(res.html);
		}
	};
	$('#kontaktform').unbind('submit').find('input:submit').unbind('click').end().ajaxForm(options);
}

function connect_form_globals(){
	$('input[@type=text],textarea').bind('focus',function(){$(this).addClass('focus');}).bind('blur',function(){$(this).removeClass('focus')});
	$('input.form-submit').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')})
}

function connect_register_form(){
	connect_form_globals();
	switch($('input[@name=type]').val()) {
		/* studoshi */
		case '0':
			$.connect_update_price('start');
			$('#park,#double,#additional').hide();
			$('select[@name=hotel]').unchange().change(function(){
				if ($(this).val()=="-1") {
					$.connect_update_price('start');
					connect_animate($('#park'),'hide',600);
				} else {
					$.connect_update_price('full');					
					connect_animate($('#park'),'show',600);
				}
			});
			$('select[@name=date]').unchange().change(function(){
				switch ($(this).val()) {
					case '0':
						$.connect_update_price('full');
						break;
					case '1':
					case '2':
						$.connect_update_price('half');
						break;
				}
			});
			$('#fellowship').click(function(){ $.connect_update_price('fellowship',this.checked); })
			break;
		/* profesionalci */	
		case '1':
			$('#park,#double,#additional,#jmbg-wrap').hide();
			$.connect_update_price('ostart');
			$('select[@name=hotel]').unchange().change(function(){
				if ($(this).val()=="-1") {
					$.connect_update_price('ostart');
					connect_animate($('#park'),'hide',600);
				} else {
					$.connect_update_price('pro');
					connect_animate($('#park'),'show',600);
				}
			});
			$('#jmbg').click(function(){
				if (this.checked) {
					connect_animate($('#jmbg-wrap'),'show',600);
				} else {
					connect_animate($('#jmbg-wrap'),'hide',600);
				}
			})
			break;
		/* korporativci */
		case '2':
			$('#park,#double,#additional').hide();
			$('input[@name=passport]').bind('keydown', function(e){
				if (e.keyCode == 8) return true;
				return ('1234567890'.indexOf(String.fromCharCode(e.keyCode))!=-1);
			});
			$('input[@name=passport]').bind('keyup', function(e){
				$.connect_update_price('persons', $(this).val()||0);
			});
			$.connect_update_price('ostart');
			$('select[@name=hotel]').unchange().change(function(){
				if ($(this).val()=="-1") {
					connect_animate($('#park'),'hide',600);
				} else {
					connect_animate($('#park'),'show',600);
				}
			});
			$('select[@name=expo]').unchange().change(function(){
				$.connect_update_price('expo', $(this).val());
			});
			$('#banner').click(function(){ $.connect_update_price('banner',this.checked); })
			$('select[@name=book]').unchange().change(function(){
				switch ($(this).val()) {
					case '0':
						$.connect_update_price('nobook');
						break;
					case '1':
						$.connect_update_price('bookbw');
						break;
					case '2':
						$.connect_update_price('bookfc');
						break;
				}
			});
			$('#presentation').click(function(){ $.connect_update_price('presentation',this.checked); })
			break;
	}
	
	var options = {
		dataType: 'json',
		before: function(formArray, jqForm) {
			$('form *').removeClass('error');
			error = false;
			if ($.trim($('input[@name=address]').val())==""){
				$('input[@name=address]').addClass('error');
				if (!error) error = 'address';
			}
			if ($.trim($('input[@name=city]').val())==""){
				$('input[@name=city]').addClass('error');
				if (!error) error = 'city';
			}
			if ($.trim($('input[@name=passport]').val())==""){
				$('input[@name=passport]').addClass('error');
				if (!error) error = 'passport';
			}
			if ($('#jmbg').length&&$('#jmbg')[0].checked) {
				if ($.trim($('input[@name=idno]').val())==""){
					$('input[@name=idno]').addClass('error');
					if (!error) error = 'idno';
				}
			}
			if (error != '') {
				$('form *[@name='+error+']')[0].focus();
				connect_progress('Please fill in all required fields..');
				return false;
			} else {
				connect_progress('Sending..');
			}
		},
		after: function(res){
			$('form *[@name]').removeClass('error');
			if (res.status == 'ok') {
				$('input[@type=text],textarea').val('');
				$('input[@type=checkbox]').each(function(){this.checked=false;})
				$('select').val("-1");
				$('#park,#double,#additional').hide();
				if ($('input[@name=type]').val()==0) $.connect_update_price('start');
				else $.connect_update_price('ostart');
			}	else 	{
				$.each(res.error, function(i,n){ 
					$('form *[@name='+n+']').addClass('error');
					if (i==0)$('form *[@name='+n+']')[0].focus();
				});
			}
			connect_progress(res.html);
		}
	};
	$('#registerform').unbind('submit').find('input:submit').unbind('click').end().ajaxForm(options);
}
jQuery.extend({
	startakus: new Array(),
	prices: {presentation: 3100, ostart: 0, start: 100, full: 350, half: 250, fellowship: 0, pro: 250, expo: 405, banner: 750, bookbw: 450, bookfc: 610, persons:0},
	connect_update_price: function(action, bool) {
		switch (action) {
			case 'ostart':
				$.each(jQuery.prices, function(i,n) {
					if (i == 'ostart') jQuery.startakus[i] = true;
					else jQuery.startakus[i] = false;
				})
				break;
			case 'start':
				$.each(jQuery.prices, function(i,n) {
					if (i == 'start') jQuery.startakus[i] = true;
					else jQuery.startakus[i] = false;
				})
				break;
			case 'full':
				$.each(jQuery.prices, function(i,n) {
					if (i=='full')jQuery.startakus[i] = true;
					else if (i=='half'||i=='start')jQuery.startakus[i] = false;
				})
				break;
			case 'half':
				jQuery.startakus['full'] = false;
				jQuery.startakus['pro'] = false;
				jQuery.startakus['half'] = true;
				break;
			case 'fellowship':
				jQuery.startakus['fellowship'] = bool;
				break;
			case 'pro':
				$.each(jQuery.prices, function(i,n) {
					if (i=='pro')jQuery.startakus[i] = true;
					else if (i=='half'||i=='start')jQuery.startakus[i] = false;
				});
				break;
			case 'expo':
				jQuery.startakus['expo'] = true;
				jQuery.prices.expo = bool*405;
				break;
			case 'banner':
				jQuery.startakus['banner'] = bool;
				break;
			case 'nobook':
				jQuery.startakus['bookbw'] = false;
				jQuery.startakus['bookfc'] = false;
				break;
			case 'bookbw':
				jQuery.startakus['bookbw'] = true;
				jQuery.startakus['bookfc'] = false;
				break;
			case 'bookfc':
				jQuery.startakus['bookbw'] = false;
				jQuery.startakus['bookfc'] = true;
				break;
			case 'persons':
				jQuery.startakus['persons'] = true;
				jQuery.prices.persons = bool*250;
				break;
			case 'presentation':
				jQuery.startakus['presentation'] = bool;
				break;
		}
		
		var price=0;
		$.each(jQuery.prices, function(i,n) {
	    if (jQuery.startakus[i]) price+=n;
		})
		if (jQuery.startakus['fellowship']&&!jQuery.startakus['half'])price-=50;
		else if (jQuery.startakus['fellowship']&&jQuery.startakus['half'])price-=50;
		$('#price').html(price+'EUR');
	}
});
function connect_progress(txt){
	$('#progress').css('opacity', 0).css('filter', 'alpha(opacity=0)').show().html(txt).fadeTo(400,0.8);
}
function connect_check_email(email){
	validRegExp=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
	var j=new RegExp()
	j.compile("[A-Za-z0-9._-]+@[^.]+\..+")
	if((email.search(validRegExp)==-1)||!j.test(email))return false
	else return true
}
function connect_start(res){
	$('#wrapper div:not(#progress):not(.content)').show();
	if ($.historyCurrentHash == ''||$.historyCurrentHash == '#index'||window.admin||window.location.href.indexOf('register.php')!=-1) 
		connect_animate($('div.content'),'show',$.speedz[$.historyCurrentHash]||1600);
	connect_register_form();
	connect_form();
}
function connect_init(){
	connect_left();
	setTimeout(connect_start,1000);
	$('#progress').css({background: '#fff'}).hide();
	$('#tab a,#left a,div.content a:not([@target])').not('.email').unclick().click(function(){
		return connect_history_load(this.href);
	});
}
function connect_history_load(url){
	if (!window.admin){
		if (window.current!=window.location.href)window.current=window.location.href;
		if (typeof url=='undefined')url='index.php'
		if (url.indexOf('program/')!=-1) pos=url.indexOf('/program/');
		else if (url.indexOf('partners/')!=-1) pos=url.indexOf('/partners/');
		else pos=url.lastIndexOf("/");
		url=url.substr(pos+1,url.length).replace('.php','').replace(/^#/, '');
		$.historyLoad(url);
		urchinTracker(url);
	} else {
		connect_load_page(url);
	}
	return false;
}
function connect_left() {
	if (!window.admin)
		$('#left').flash(
        { src: 'swf/left47.swf', width: 380, height: 500, id: 'left_flash', flashvars: {active: document.location.href}, bgcolor: '#ffffff', allowScriptAccess: 'always'},
        { version: 8, expressInstall: true, update: false },
				function(htmlOptions){
					$(this)[0].innerHTML = jQuery.fn.flash.transform(htmlOptions);
				}
    );
	else $('#left').empty();
}
function connect_settitle(){
	if (!window.admin) {
		if ($.historyCurrentHash.length > 1) title = $.pagetitles[$.historyCurrentHash]||$.historyCurrentHash.replace(/^#/, '').replace(/_/g,' ');
		else title = 'About';
		document.title="PharmaCon2007 - "+title.toProperCase();	
	}
}