function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggleHomepageLead (toggle) {
	$(document).ready(function(){
		if ( toggle == 1 ) {
		   $("#bannerleads").show();
		   //$("#testdrivewrapper").css('visibility','visible');
		} else if ( toggle == 0 ) {
		   $("#bannerleads").hide();
		   //$("#testdrivewrapper").css('visibility','hidden');
		}
	});
}

function flashTrackEvent(category, action, label, value) {
	if( value==undefined || value == "" ) _gaq.push(['_trackEvent', category, action, label]);
	else _gaq.push(['_trackEvent', category, action, label, value]);
	//alert(category+" / "+action+" / "+label);
}

function numberFormat ( number ) {
  laenge = "2";
  sep = ".";
  th_sep = ".";
  number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
  str_number = number+"";

  arr_int = str_number.split(".");
  if(!arr_int[0]) arr_int[0] = "";
  if(!arr_int[1]) arr_int[1] = "";
  if(arr_int[1].length < laenge){
    nachkomma = arr_int[1];
    for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
    arr_int[1] = nachkomma;
  }
  if(th_sep != "" && arr_int[0].length > 3){
    Begriff = arr_int[0];
    arr_int[0] = "";
    for(j = 3; j < Begriff.length ; j+=3){
      Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
      arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
    }
    str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
    arr_int[0] = str_first + arr_int[0];
  }
  //return arr_int[0];
  return arr_int[0]; //+sep+arr_int[1];
}

hcb = null;
function configurator_hashchange (pageurl) {
    hcb = false;
    $(window).hashchange ( function(){
        if ( hcb == false ) {
            _hash = location.hash.replace ('#', '');
            if ( _hash == "" ) {
                _hash = "step-0";
            }
            $("#configurator_container").load ('/'+pageurl+_hash+'-ajax-1');
        }
    });
}

$(document).ready(function(){
    
	$.ajaxSetup ({
		cache: false
	});    
    
    // colorbox
	$(".colorbox").colorbox({maxHeight:"95%"});
    
    // harta site
    $("#hartasitelink").click (function () {
        $("#hartasitediv").toggle ();
        return false;
    });
	
	/*Cufon.replace( $("#menu"), {ignoreclass : {notcufon : true}, ignore : {small : true}, hover: true} );
	Cufon.replace( $("#menu_dealer"), {ignoreclass : {notcufon : true}, ignore : {small : true}, hover: true} );
	Cufon.replace('#baramasini');
	Cufon.replace('.logo-dealer');
	Cufon.replace('#leftmenu',{fontFamily: 'alpha-normal', hover: true});
	Cufon.replace('#homeleads div.title',{fontFamily: 'alpha-normal'});
	Cufon.replace('#homeleads .newsletter h2',{fontFamily: 'alpha-normal'});
	Cufon.replace('#homeleads p a',{fontFamily: 'alpha-normal'});
	Cufon.replace('.dealerscont h2',{fontFamily: 'alpha-normal'});
	Cufon.replace('h1',{fontFamily: 'alpha-normal'});
	Cufon.replace('.reteahome h2',{fontFamily: 'alpha-normal'});
	Cufon.replace('h3');
	Cufon.replace('h4',{textShadow: '#000 1px 1px, #666 -1px -1px'});*/
    
    // landing page
    $.get ("/cmsmodule/landing-page", {page : window.location.href, domain : window.location.host}, function (data) {
        if ( data.load == true ) {
            $('body').prepend (data.html);
            
            $("#overlaylink").click(function () {
            	$('body').removeClass('overlay');
            	$('#overlay').hide();
            	$('#wrapper').show();
                $('.container_16').show();
                return false;
            });
                        
        	$('body').addClass('overlay');
        	$('#wrapper').hide();
            $('.container_16').hide();
       	    //pageTracker._trackPageview (data.ga);
        }
    }, 'json');
    
    // mobile detector
    $.get ("/cmsmodule/mobile-detector", {}, function (data) {
        if ( data.load == true ) {
            $('body').prepend (data.html);
            
            $("#sitelink").click(function () {
            	$('body').removeClass('overlay');
            	$('#overlay').hide();
            	$('#wrapper').show();
                return false;
            });
                        
        	$('body').addClass('overlay');
        	$('#wrapper').hide ();                                                
        }
    }, 'json');
});
