﻿

var BASE_URL = 'http://www.vamplets.com/';
var XML_URL = BASE_URL + 'includes/xml/';
	
function clearErrors(parentid) {
	$('#' + parentid + ' .errors').remove();
}

function addErrors(errors, parentid){
	var div = $(document.createElement(div));
	var html = '';
	div.attr({className: 'errors'});
	for(var i = 0, len = errors.length;i<len;i++)
		html += '<br />*' + errors[i];
	div.html(html);
	$('#' + parentid).append(div);
}

function dataHasErrors(data, parentid){
	if($(data).find('status').text() == 'ACK') return false;
	var errors = [];
	$(data).find('errors *').each(function(){
		errors[errors.length] = $(this).text();
	});
	if(errors.length == 0)
		errors[errors.length] = "An unknown error occured.";
	addErrors(errors, parentid);
	return true;
}

function setCookie(name, val){
	document.cookie = name+'='+val+'; path=/;';
}

function getCookie(name) {
	var cookies = document.cookie.split('; ')
	var name_value = [];
	for(var i = 0;i < cookies.length;i++){
		name_value = cookies[i].split('=');
		if(name_value.length != 2) continue;
		if(name_value[0] == name)
			return name_value[1];
	}
	return '';
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

var history_last_was_add = false;
var history_start = false;
var history_start_hash = document.location.hash.length > 1 ? document.location.hash.replace("#", "") : "Landing.swf";

function addToHistory(hash) {
	history_last_was_add = true;
	$.historyLoad(hash);
}

function onBack(hash){
	if(!history_start){
		history_start_hash = hash;
		return;
	}
	if(history_last_was_add){
		history_last_was_add = false;
		return;
	}
	history_last_was_add = false;

	if(hash == "") 
		history.go(-1);
	else{
		thisMovie("vamplets_world").setDeepLink(hash);
}
}

function start_vamplets() {
	history_start = true;
	$.historyLoad(history_start_hash);
}

$(document).ready(function(){
	try{
		$.historyInit(onBack, BASE_URL);
	}catch(e){}
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22842605-1']);
_gaq.push(['_setDomainName', '.vamplets.com']);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();

