$(document).ready(function(){
	// Startpage News Scroller
	$(".scrollable").scrollable({ circular: true }).autoscroll({ autoplay: true , interval: 5000 });
	//$(".scrollable").scrollable().autoscroll({ autoplay: true });
	
	// Startpage Teaser Scroller
	$(".startpage-teaser-scrollable").scrollable();
	
	// Startpage Tabs
	$("ul.tabs").tabs("div.panes > div");
	
	//Set font size
	fontResizer('1em','1.1em','1.2em');
	
	//Set staging slider
	$('#demo').Horinaja({capture:'demo',delai:0,duree:8,pagination:true});
	
	//Tabs
	$('div.tab-content>div').hide();
	$('div.tab-content>div:first').show();
	$('ul.tab-headline li:first').addClass('active');

	$('ul.tab-headline li a').click(function(){ 
		$('ul.tab-headline li').removeClass('active');
		$(this).parent().addClass('active'); 
		var currentTab = $(this).attr('href'); 
		$('div.tab-content>div').hide();
		$(currentTab).show();
		return false;
	});
	
	//External Link leave notice
	$('a[target=_blank]').leaveNotice();

	//Equal div height
	$('div.sitemap > div').syncHeight();
	
	//Form branch vals
	function branchVals() {
    var branchArea = $("select#branch-area").val();
		if(branchArea==0){
			$("div#branch-location input").val("- - -");
			$("div#branch-email input").val("vertrieb@thgeyer.de");
			$("div#branch-plz").show();
		}
		if(branchArea==1){
			$("div#branch-location input").val("Niederlassung Höxter");
			$("div#branch-email input").val("rohstoffe@thgeyer.de");
			$("div#branch-plz").hide();
		}  			  		
    }
    $("select#branch-area").change(branchVals);
    branchVals();

	// Tooltip
	$("form.search-field input[alt]").qtip({
	   position: {
		  corner: {
			 tooltip: 'topLeft', // Use the corner...
			 target: 'rightBottom' // ...and opposite corner
		  }
	   },
	   style: {
		  border: {
			 width: 1,
			 radius: 3
		  },
		  padding: 3, 
		  textAlign: 'center',
		  tip: true, // Give it a speech bubble tip with automatic corner detection
		  name: 'light' // Style it according to the preset 'cream' style
	   }
	});
	
	
	
	
	
	$('#customerid').val($('#customerid').attr("alt"));
	
	
	//$('#customerid').click(function() {
	$('#customerid').focusin(function() {
	    if ($(this).val() == $(this).attr('alt')) {
	    	$(this).val('');
	    }
	});
	
	$('#customerid').focusout(function() {
	    if ($(this).val() == "") {
	    	$(this).val($(this).attr('alt'));
	    }
	});
	
	
	$('#username').val($('#username').attr('alt'));
	
	$('#username').click(function() {
	    if ($(this).val() == $(this).attr('alt')) {
	    	$(this).val('');
	    }
	});
	
	$('#username').focusout(function() {
	    if ($(this).val() == "") {
	    	$(this).val($(this).attr('alt'));
	    }
	});
	
	// disabled, this produces js-errors nullacht15 20120214
	//document.shoplogin.password.type = 'text';
	
	
	$('#password').val($('#password').attr('alt'));
	
	$('#password').bind('focus click', function() {
		// disabled, this produces js-errors nullacht15 20120214
   		//$('#password').attr('type', 'password');
		//document.shoplogin.password.type = 'password';
	
	    if ($(this).val() == $(this).attr('alt')) {
	    	$(this).val('');
	    }
	});
	
	$('#password').focusout(function() {
	    if ($(this).val() == "") {
	    	$(this).val($(this).attr('alt'));
	    }
	    
	    if ($(this).val() == $(this).attr('alt') || $(this).val() == "") {
	    	// disabled, this produces js-errors nullacht15 20120214
			//$('#password').attr('type', 'text');
	    	//document.shoplogin.password.type = 'text';
	    } 
	});
	
	checkForShopCookie();
	

	
	
	
});	

// Language Selector
function changeCountry(cSel) {
  if( cSel != null ) {
    var selVal = cSel.options[cSel.selectedIndex].value

    switch (selVal) {
      case "0":
        // alert("http://www.thgeyer.de/");
        window.location = "http://home.thgeyer.de/home/";
        break;
      case "1":
        // alert("http://www.thgeyer.com/");
        window.location = "http://home.thgeyer.com/home/";
        break;
      case "2":
        // alert("http://www.thgeyer.dk/");
        window.location = "http://home.thgeyer.dk/home/";
        break;
    }
  }
}

/* ------------------------------------------- */
/*             SHOP ANMELDUNG                  */
/* ------------------------------------------- */
var bites;
if(document.cookie){
 bites = document.cookie.split("; ");
} else {
 bites = new Array();
}
var cookieName = "thgeyerShop";
var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days
var expired = new Date(today.getTime() - 28 * 24 * 60 * 60 * 1000); // less 28 days
 
function getCookie(name) {
 for (i=0; i < bites.length; i++) {
  nextbite = bites[i].split("="); // break into name and value
  if (nextbite[0] == name){
   return unescape(nextbite[1]);
  }
 }
 return null;
}

function setCookie(name, value) {
 if (value != null && value != ""){
  document.cookie=name + "=" + escape(value) + ";path=/; expires=" + expiry.toGMTString();
  bites = document.cookie.split("; "); // update cookie bites
 }
}

function deleteCookie(name) { // use: deleteCookie("name");
 document.cookie=name + "=null; expires=" + expired.toGMTString(); // delete cookie
 bites = new Array();
}

function checkForShopCookie()
{
  if(document.shoplogin != null && navigator.cookieEnabled) {
    if(getCookie(cookieName) == null) {
      return;
    }
    cookieValueArray=getCookie(cookieName).split("!");
    if(!isNaN(cookieValueArray.length)) {
        var login_accountnr = cookieValueArray[0];
        var login_username =  cookieValueArray[1];
        document.shoplogin.kunde.value = login_accountnr;
        document.shoplogin.login.value = login_username;
        document.shoplogin.storedata.checked=true
        //document.shoplogin.passwort.focus();
    }
  }
}

function setShopCookie() {
  kundennummer = document.shoplogin.kunde.value;
  if (kundennummer == document.shoplogin.kunde.alt || kundennummer == "") {
  	//alert("Geben Sie bitte Ihre Kundennummer ein");
    return false;
  }
  
  benutzername=document.shoplogin.login.value;
  if (benutzername == document.shoplogin.login.alt || benutzername == "") {
  	benutzername="";
  	document.shoplogin.login.value = '';
  }
  
  if (document.shoplogin.storedata.checked) {
  	cookieValue=kundennummer+"!"+benutzername;
    setCookie(cookieName,cookieValue);
  } else if(document.cookie){
  	deleteCookie(cookieName);
  }
 
  return true;
  
}


