/*
 * //////////////////////////////////////COPYRIGHT © 2009 SACHSEN DV
 * //////////////////////////////////////////////ALL RIGHTS RESERVED
 * /////////LICENSED UNDER THE SDV LICENSE VERSION 1.0 [THE LICENSE]
 * ///////DO NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE LICENSE
 */
//@version $Id: layout.js 5756 2011-07-12 10:12:14Z twagner $


////////////////////////////////////////////////////////CUFÓN STYLES
var swb = '-linear-gradient(#ffffff, #cccccc)';
var shb = '#ffffff 1px 1px, #bbbbbb -1px -1px';
var shm = '#666666 1px 1px, #444444 -1px -1px';
var shd = '#666666 1px 1px, #444444 -1px -1px';



//if($.browser.msie) {
  Cufon.replace('h1 span,h2,a.submit', {
  	color: '#fff'
  });
  Cufon.replace('ul.hdr-nav a', {
  	color: '#fff'
  });
  Cufon.replace('div.phn', {
  	color: '#fff'
  	,textShadow: shb
  });
//}


////////////////////////////////////////////////////////////////VARS
////////////////////////////////////////////////////////////////////

var cls = "active";
var ie6 = $.browser.msie && $.browser.version.substr(0,1)<7 ? true : false;

////////////////////////////////////////////////////////////DEFAULTS
////////////////////////////////////////////////////////////////////

$(document).ready(function() {
	$("form").validationEngine();
	$("table tr:nth-child(odd)").addClass("odd");
	$(".icns:nth-child(even)").addClass("even");
	$("textarea").focusin(function() {
		var s = $(this).val().toString();
		if(s == " ") {
			$(this).select();
		}
	});
	
	var winname = "OX Portal";
	$('a.ext').click(function(){
		window.open($(this).attr('href'),winname);
		window.focus(winname);
		return false;
	});
});





///////////////////////////////////////////////////////////////POPUP
////////////////////////////////////////////////////////////////////

var pps = 0;
var fdt = 400;
$(document).ready(function() {
	
	$(".vid").click(function(){
		if(pps == 0) {
			var vid = $(this).attr("href");
			ppcreate(vid);
			pppos();
			ppstart();
		}
	});

	$(window).scroll(function () { 
		if(pps == 1 && !ie6) {
			var top = $(window).height()/2 - $("#ppctr").height()/2;
			var stp = $("#ppctr").offset().top;
			//$("#ppctr").text( "top:" + top + " scrolltop:" + stp);
			//$("#ppctr").animate({top: stp}, 200);
		}
	});
	$(window).resize(function () { 
		if(pps == 1 && !ie6) {
			var top = $(window).height()/2 - $("#ppctr").height()/2;
			var lft = $(window).width()/2 - $("#ppctr").width()/2;
			$("#ppctr").animate({top: top, left: lft}, 200);
		}
	});
	
	
	$("#ppbg").click(function() {
		if(pps == 1) {
			ppstop();
		}
	});
	
	$(document).keypress(function(e) {
		if(e.keyCode==27 && pps == 1){
			ppstop();
		}
	});
});





function ppstart(){	
	$("#ppbg").fadeTo(fdt, 0.65, function () {
		$("#ppctr").fadeIn(fdt);
//		$("#ppctr").fadeIn(450, function () {
//			$("#ppobj").fadeIn(100);
//		});
	});
	pps = 1;
}

function ppcreate(vid){
	var fla = vid;
	var img = "res/images/cnt-01.png";

	$("body").append('<div id="ppbg" onclick="ppstop();">&#160;</div>');
	$("#ppbg").css("opacity",0);
	
	$("body").append('<div id="ppctr"></div>');
	$("#ppctr").append('<object id="ppobj" type="application/x-shockwave-flash"'+
			'data="' + fla + '"'+
	        'width="100%" height="100%">'+
	        '<param name="movie" value="' + fla + '" />' +
	        '<param name="allowscriptaccess" value="sameDomain" />'+
	        '<param name="quality" value="high" />'+
	        '<param name="wmode" value="transparent" />'+
	        '<!--param name="bgcolor" value="white" /-->'+
	        '<param name="scale" value="scaletofit" />'+
	        '<param name="salign" value="tl" />'+
	        '<param name="menu" value="false" />'+
	        '<param name="flashvars" value="" />'+
	        '<img src="' + img + '" alt="TEST" />'+
	      '</object>');
	$("#ppctr").append('<div id="ppcls" onclick="ppstop();">x</div>');
}

function pppos(){
	if(!ie6) {
		var top = $(window).height()/2 - $("#ppctr").height()/2;
		var lft = $(window).width()/2 - $("#ppctr").width()/2;
		
		$("#ppctr").css("top",top);
		$("#ppctr").css("left",lft);
	}
}

function ppstop(){
	$("#ppctr").fadeOut(fdt, function () {
		$("#ppbg").fadeOut(fdt, function () {
			$("#ppctr").remove();
			$("#ppbg").remove();
			pps = 0;
		});
	});
}




////////////////////////////////////////////////////////////////INFO
////////////////////////////////////////////////////////////////////

$(document).ready(function () {
	var id = null;
	var src = "";
	var res = "res/icons/";
	
	$(".info > li").mouseover(function () {
		id = this.id;
		src = $(this).children("img").attr("src");
		$(this).children("img").attr("src", res + id + "ON.png");
    }).mouseout(function () {
		$(this).children("img").attr("src", src);
    });
});




////////////////////////////////////////////////////////////CAROUSEL
////////////////////////////////////////////////////////////////////

$(document).ready(function () {

  var loop = 8000;
  var fade = 600;
  var cls = ".fade";
  var itm = "img";
  var lft = $(cls + ' :first-child').css("left");
  $(cls).css("height",$(cls + ' :first-child').css("height"));
  $(cls + ' ' + itm + ':gt(0)').hide();
  $(cls + ' ' + itm + ':eq(0)').show();
  setInterval(function(){
    if ($.browser.msie) {
      $(cls + ' :first-child').animate({
        left: '+=1000'
      }, fade, function() {
        $(this).hide();
        $(this).css("left",lft);
        $(this).next(itm).show();
        $(this).appendTo(cls);
      });
    } else {
      $(cls + ' :first-child').fadeOut(fade, function() {
        $(this).next(itm).fadeIn();
        $(this).appendTo(cls);
      });
    }
  },loop);
});





////////////////////////////////////////////////////////////VALIDATE
////////////////////////////////////////////////////////////////////


var vengineloc = 	{
	"required":{  
		"regex":"none",
		"alertText":"Pflichtfeld",
		"alertTextCheckboxMultiple":"Bitte eine Option wählen",
		"alertTextCheckboxe":"Pflichtfeld"},
	"length":{
		"regex":"none",
		"alertText":"Zwischen ",
		"alertText2":" und ",
		"alertText3": " Zeichen erlaubt"},
	"maxCheckbox":{
		"regex":"none",
		"alertText":"Maximale Anzahl überschritten"},	
	"minCheckbox":{
		"regex":"none",
		"alertText":"* Bitte wählen Sie ",
		"alertText2":" Optionen"},	
	"confirm":{
		"regex":"none",
		"alertText":"Dieses Feld hat keine übereinstimmung"},		
	"telephone":{
		"regex":"/^[0-9\-\(\)\ ]+$/",
		"alertText":"ungültige Telefonnummer"},
	"email":{
		"regex":"/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/",
		"alertText":"ungültige E-Mailadresse"},	
	"date":{
		"regex":"/^[0-9]{4}\-\[0-9]{1,2}\-\[0-9]{1,2}$/",
		"alertText":"ungültiges Datum - bitte in Format YYYY-MM-DD eingeben"},
	"onlyNumber":{
		"regex":"/^[0-9\ ]+$/",
		"alertText":"nur Zahlen erlaubt"},	
	"noSpecialCaracters":{
		"regex":"/^[0-9a-zA-Z]+$/",
		"alertText":"keine Sonderzeichen erlaubt"},	
	"ajaxUser":{
		"file":"validateUser",
		"alertTextOk":"* This user is available",	
		"alertTextLoad":"* Loading, please wait",
		"alertText":"* This user is already taken"},	
	"ajaxName":{
		"file":"validateUser",
		"alertText":"* This name is already taken",
		"alertTextOk":"* This name is available",	
		"alertTextLoad":"* Loading, please wait"},		
	"onlyLetter":{
		"regex":"/^[a-zA-Z\ \']+$/",
		"alertText":"nur Buchstaben erlaubt"}
};



///////////////////////////////////////////////////////////FUNCTIONS
////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////
//http://andreaslagerkvist.com/jquery/equal-height/
//http://tomdeater.com/jquery/equalize_columns/jquery.equalizecols.js
//EQUALHEIGHT

$.fn.equalHeight = function() {
	var height = 0;
	var	reset = $.support.objectAll ? "1%" : "auto";
	
	return this
		.css("height", reset)
		.each(function() {
			height = Math.max(height, this.offsetHeight);
		})
		.css("height", height)
		.each(function() {
			var h = this.offsetHeight;
			if (h > height) {
				$(this).css("height", height - (h - height));
			};
		});
};


////////////////////////////////////////////////////////////////////
//GETINDEX

$.fn.getIndex = function(){
	//var $p = $(this).parent().children().index($(this))
	var $p = $(this).parent().prevAll().length;
	return $p;
};


////////////////////////////////////////////////////////////////////
//SLIDE UP
//siderite.blogspot.com/2009/08/jquery-slideup-flickers-in-internet.html

$.fn.clipUp = function(speed){
	var h = $(this).height();
	var ch = $(this).css('height');
	$(this).animate( 
		{ height: '1px' }, 
		speed, 
		function() { 
			$(this).hide();
			$(this).height(h);
			$(this).css('height',ch);
			//callBack(); 
		} 
	);
};




/**
 * Helper function for printing out debug messages.
 */
function log(s) {
    // Log to Firebug (getfirebug.com) if available
    if (window.console != undefined && typeof window.console.log == 'function')
        console.log(s);
};
