//var ROOT_URL  = 'http://southpark.dev/';
var ROOT_URL = 'http://www.southpark.ro/';

function hoverObject(obj) {
	if (obj.className.indexOf('hovered') == -1) obj.className += ' hovered';
	else obj.className = obj.className.replace("hovered", "");
}

function emulateSelectBehaviour(triggerObj, code) {

	var uls = triggerObj.parentNode.getElementsByTagName('ul');
	var uls_no = uls.length;
	if (uls_no == 0) return false;

	if (uls[0].style.display == 'none' || uls[0].style.display == '') uls[0].style.display = 'block';
	else uls[0].style.display = 'none';

}

function redirect(url){
	window.location.href = ROOT_URL + url;
}

function mouseOver(obj) {
	obj.style.backgroundColor = '#fff';
	//var ps = obj.getElementsByTagName('p');
	var h3s = obj.getElementsByTagName('a');
	//ps[0].style.textDecoration = "underline";
	h3s[0].style.textDecoration = 'underline';

}
function mouseOut(obj) {
	obj.style.backgroundColor = '#fff';
	//var ps = obj.getElementsByTagName('p');
	var h3s = obj.getElementsByTagName('a');
	//ps[0].style.textDecoration = "none";
	h3s[0].style.textDecoration = 'none'
}
function goToChildAddress(obj) {
	var as = obj.getElementsByTagName('a');
	document.location = as[0].href;
}

function validate_required(field)
{
	with (field)
	{
		if (value==null || value=="") {
			document.getElementById("cf_"+field.name).style.display="block";
			return false;
		} else {
			document.getElementById("cf_"+field.name).style.display="none";
			return true;
		}
	}
}

function validate_email(field)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");

		if (apos<1||dotpos-apos<2) {
			document.getElementById("cf_"+field.name).style.display="block";
			return false;
		} else {
			document.getElementById("cf_"+field.name).style.display="none";
			return true;
		}
	}
}

function validate_form(thisform)
{

with (thisform)
	{
		var errors = 0;

		if (validate_required(name)==false)
		  {errors++;}
		if (validate_required(phone)==false)
		  {errors++;}
		if (validate_required(email)==false)
		  {errors++;}
		if (validate_email(email)==false)
		  {errors++;}
		if (validate_required(message)==false)
		  {errors++;}
	if (errors > 0) { return false; }
	}
}

var curRotPosition = 1;
var stopRotation = 0;

function startRotationx(obj, start) {

	obj.onmouseover = function() {stopRotationx(start);}
	window.stopRotation = 0;
	window.curRotPosition = start;
	startRotation(start);

}

function stopRotationx(obj, breakpoint) {

	obj.onmouseover = function() {}
	window.stopRotation = 1;

	var uls = document.getElementsByTagName('ul');
	var uls_no = uls.length;
	if (uls_no < 3) return false;
	var f_pointer = 0;

	for (var i = 1; i <= uls_no; i++) {
		var pointer = i-1;
		if (uls[pointer].className.indexOf('articles') != -1) {
			if (pointer == 2 && breakpoint == 1) f_pointer = 2;
			else if (pointer == 3 && breakpoint == 2) f_pointer = 3;
			else if (pointer == 5 && breakpoint == 3) f_pointer = 5;
			else {
				var imgs = uls[pointer].getElementsByTagName('img');
				imgs[0].src = imgs[0].src.replace("_selected", "");
				uls[pointer].className = uls[pointer].className.replace(" selected", "");
			}
		}
	}

	if (uls[f_pointer].className.indexOf('selected') == -1) {
		var imgs = uls[f_pointer].getElementsByTagName('img');
		imgs[0].src = imgs[0].src.replace(".jpg", "_selected.jpg");
		uls[f_pointer].className += " selected";
	}

}

function startRotation(start) {

	window.curRotPosition = start;
	var parkingtime = 10000;
	if (window.stopRotation == 1) return false;

	var uls = document.getElementsByTagName('ul');
	var uls_no = uls.length;
	if (uls_no < 3) return false;
	var f_pointer = 0;

	for (var i = 1; i <= uls_no; i++) {
		var pointer = i-1;
		if (uls[pointer].className.indexOf('articles') != -1) {
			if (pointer == 2 && start == 1) f_pointer = 2;
			else if (pointer == 3 && start == 2) f_pointer = 3;
			else if (pointer == 5 && start == 3) f_pointer = 5;
			else {
				var imgs = uls[pointer].getElementsByTagName('img');
				imgs[0].src = imgs[0].src.replace("_selected", "");
				uls[pointer].className = uls[pointer].className.replace(" selected", "");
			}
		}
	}

	if (uls[f_pointer].className.indexOf('selected') == -1) {
		var imgs = uls[f_pointer].getElementsByTagName('img');
		imgs[0].src = imgs[0].src.replace(".jpg", "_selected.jpg");
		uls[f_pointer].className += " selected";
	}

	if (start == 1) window.setTimeout("startRotation(2);", parkingtime);
	if (start == 2) window.setTimeout("startRotation(3);", parkingtime);
	if (start == 3) window.setTimeout("startRotation(1);", parkingtime);

}

function selectThis(obj) {

	var uls = document.getElementsByTagName('ul');
	var imgs = obj.getElementsByTagName('img');
	var imgs_no = imgs.length;
	var uls_no = uls.length;
	if (uls_no < 3 || imgs_no < 1) return false;

	for (var i = 1; i <= uls_no; i++) {
		var pointer = i-1;
		if (uls[pointer].className.indexOf('articles') != -1) {
			var imgs = uls[pointer].getElementsByTagName('img');
			imgs[0].src = imgs[0].src.replace("_selected", "");
			uls[pointer].className = uls[pointer].className.replace(" selected", "");
		}
	}

	imgs[0].src = imgs[0].src.replace(".jpg", "_selected.jpg");
	obj.className += " selected";

}

function focusThis(obj) {
	return false;
	obj.style.borderRightColor = "#e6b1ff";
	obj.style.fontWeight = "bold";
}

function blurThis(obj) {
	obj.style.borderRightColor = "#dedede";
	obj.style.fontWeight = "normal";
}

function decideVisual() {

	if ((screen.width>=1024) && (screen.height>=768) && 1==1) {
		var h = document.getElementById('header');
		var hb = document.getElementById('header_big');
		var hc = document.getElementById('header_container');
		h.style.display = 'none';
		hb.style.display = 'block';
		hc.style.width = '1200px';
	}

}

function targetLinks() {

	var as = document.getElementsByTagName('a');
	as_no = as.length;
	if (as_no == 0) return false;

	for (var i = 0; i < as_no; i++) {
		if (as[i].rel == 'external') as[i].target = "_blank";
	}

}

/**
 * Embeds a SWF into a page using the given options
 *
 * @param {Object} options
 */
var embedSWF = function(options)
{
	var defaults = {
		url: ROOT_URL,
		container: 'elementID',
		width: 500,
		height: 350,
		flashVars: {},
		parameters: {
			quality: 'high',
			menu: false,
			wmode: 'transparent'
		},
		attributes: {}
	};

	if(options == undefined || options == null)
	{
		options = defaults;
	}
	else
	{
		// Allow skipping certain options to be set to the default values
		// You can pass in only the options you want to override
		for(var x in defaults)
		{
			eval('if(!options.' + x + ') options.' + x + ' = defaults.' + x + ';');
		}
	}

	swfobject.embedSWF(options.url, options.container, options.width, options.height, '9.0.0', '', options.flashVars, options.parameters, options.attributes);
}

var embedHeader = function()
{
	var h = document.getElementById('header');
	var hb = document.getElementById('header_big');
	var hc = document.getElementById('header_container');

	if ((screen.width>1024) && (screen.height>768)) {
		h.style.display = 'none';
		hb.style.display = 'block';
		hc.style.width = '1200px';
		embedSWF({url: ROOT_URL + '&resources/flash/header-1200.swf', container: 'header_big', width: 1200, height: 334});
	}
	else
	{
		h.style.display = 'block';
		hb.style.display = 'none';
		hc.style.width = '990px';
		embedSWF({url: ROOT_URL + '&resources/flash/header-990.swf', container: 'header', width: 990, height: 334});
	}
}

var embedFaza1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/faza1.swf', container: 'faza1SWF', width:622, height:420, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/faza1.xml'}});
}

// Bloc A1
var embedBlocA1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1.swf', container: 'buildingSWF', width:418, height:244, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

var embedBlocA1Parter = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1-parter.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

var embedBlocA1Etaj1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1-etaj1.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

var embedBlocA1Etaj2 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1-etaj2.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

var embedBlocA1Etaj3 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1-etaj3.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

var embedBlocA1Etaj4 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocA1-etaj4.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocA1.xml'}});
}

// Bloc B1
var embedBlocB1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1.swf', container: 'buildingSWF', width:418, height:244, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

var embedBlocB1Parter = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1-parter.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

var embedBlocB1Etaj1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1-etaj1.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

var embedBlocB1Etaj2 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1-etaj2.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

var embedBlocB1Etaj3 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1-etaj3.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

var embedBlocB1Etaj4 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocB1-etaj4.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocB1.xml'}});
}

// Bloc C1
var embedBlocC1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocC1.swf', container: 'buildingSWF', width:418, height:244, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocC1.xml'}});
}

var embedBlocC1Parter = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocC1-parter.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocC1.xml'}});
}

var embedBlocC1Etaj1 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocC1-etaj1.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocC1.xml'}});
}

var embedBlocC1Etaj2 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocC1-etaj2.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocC1.xml'}});
}

var embedBlocC1Etaj3 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/blocC1-etaj3.swf', container: 'aptSWF', width:450, height:216, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/blocC1.xml'}});
}

// Vila T2
var embedVilaT2 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/vilaT2.swf', container: 'buildingSWF', width:418, height:244, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/vilaT2.xml'}});
}

// Vila T4
var embedVilaT4 = function()
{
	embedSWF({url: ROOT_URL + '&resources/swf/vilaT4.swf', container: 'buildingSWF', width:418, height:244, flashVars: { xmlFile: ROOT_URL + encodeURIComponent('&resources') + '/xml/vilaT4.xml'}});
}

/**
 * This function will run on page load. Add here what ever you need to be executed after the page has been fully loaded.
 */
var runInit = function()
{
	embedHeader();
}

