if(typeof Cufon != "undefined") {
	Cufon.replace('#nav2 a', {
		hover: true,
		textShadow: '#ddd 0px 1px 20px',
		fontFamily: 'medium'
	});

	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('.cufon');

	Cufon.replace('.avenir-heavy', {
		fontFamily: 'heavy'
	});
	Cufon.replace('.avenir-medium', {
		fontFamily: 'medium'
	});

	Cufon.replace('#invite_h3_heavy', {
		fontFamily: 'heavy'
	});

	Cufon.replace('.teaser_more_link h1', {
		fontFamily: 'medium'
	});

	Cufon.replace('.left_form_footer', {
		fontFamily: 'heavy'
	});

	Cufon.replace('.left_form_footer_2', {
		fontFamily: 'heavy'
	});

	Cufon.replace('.right_form_footer', {
		fontFamily: 'heavy'
	});


	Cufon.replace('.header-login_h1', {
		fontFamily: 'heavy'
	});

		Cufon.replace('.header-login_h1b', {
		fontFamily: 'heavy'
	});

		Cufon.replace('.header-login_h2', {
		fontFamily: 'medium'
	});

			Cufon.replace('.header-login_h2_1', {
		fontFamily: 'medium'
	});

			Cufon.replace('.header-login_h2_2', {
		fontFamily: 'heavy'
	});

	Cufon.replace('#field-submit h3', {
		fontFamily: 'heavy'
	});

    Cufon.replace('.action_link a', {
		fontFamily: 'medium'
	});

	Cufon.replace('.action_link .av2', {
		fontFamily: 'medium'
	});

	// Kundenkarte Seite 1 Listenpunkte
	Cufon.replace('#content_login_li li', {
		fontFamily: 'medium'
	});
	Cufon.replace('#content_login_li2 li', {
		fontFamily: 'medium'
	});


    // Sitemap

    Cufon.replace('.sitemap h2', {
		fontFamily: 'medium'
	});

     Cufon.replace('.sitemap ul li.first_li a ', {
		fontFamily: 'medium'
	});

     Cufon.replace(' .sitemap ul li.second_li a', {
		fontFamily: 'medium'
	});


    //Standorte

     Cufon.replace('.text_unten h1', {
		fontFamily: 'book'
	});

     Cufon.replace(' .text_unten h1.bold', {
		fontFamily: 'heavy'
	});
}

jQuery('document').ready(function(){
	jQuery('.open-in-popup').bind('click',function() {
		var href = jQuery(this).attr('href');
		openInPopup(href, '{fullscreen:1}');
		return false;
	});

    jQuery.fn.nyroModal.settings.endShowContent = scrollToTop;
    jQuery.fn.nyroModal.settings.endRemove = removeModalBox;

	//min width and height for flashpage
	if(document.getElementById('flashPage')) {
		minsize('layout_wrap',1240,850);
	}
	if(document.getElementById('swf_special')) {
		//minsize('page',1240,850);
		minsize('layout_wrap',1240,850);
		var page = jQuery('#page');
		var pageChildren = jQuery(page).children();
		var pageSwf = jQuery('#swf_special');
		jQuery(page).css({width: '100%', height: '100%'})
		jQuery(pageChildren).css({width: '100%', height: '100%'})
		jQuery(pageSwf).css({width: '100%', height: '100%'})
	}
	if(document.getElementById('swf_special_bluewave')) {
		minsize('layout_wrap',1240,850);
		var page = jQuery('#page');
		var pageChildren = jQuery(page).children();
		var pageSwf = jQuery('#swf_special_bluewave');
		jQuery(page).css({width: '100%', height: '100%'})
		jQuery(pageChildren).css({width: '100%', height: '100%'})
		jQuery(pageSwf).css({width: '100%', height: '100%'})
	}

	jQuery('#nav2 a[rel*=popup]').each(function(){
		if($(this).attr('onclick')) {
			$(this).removeAttr('onclick');
		}
		var rel = $(this).attr('rel').substr(6).split('x');
		var width = rel[0];
		if(width == 0) {
			width = 1077;
		}
		var height = rel[1];
		if(height == 0) {
			height = 730;
		}
		var href = $(this).attr('href');
		if(href) {
			$(this).click(function(){
				vHWin=window.open('/'+href,'FEopenLink','width='+width+',height='+height+',resizable=0,scrollbars=1');
				vHWin.focus();
				return false;
			});
		};
	});
		// console.log('StoreInfoTeaserXml: ',getStoreInfoTeaserXml());
		// console.log('myStore: ',getUserStore());

    storeBrandTabs();
    checkVCardUserStore();

function doRePadding(){
        var minWidth = 1240;
        var defPadding = 118;
        var width = jQuery(window).width();
        var target = jQuery('#content_wrap');
        var marginalTarget = jQuery('#marginal');
        var curr = parseInt(target.css('padding-left'));
        if(width > minWidth) {
            var diff = width - minWidth;
            var newVal = 0;
            if(diff < defPadding) {
                var newVal = defPadding - diff;
            }
            target.css({'padding-left': newVal});
        }
        else {
            target.css({'padding-left': 118});
        }

        if(width > (minWidth + 40)) {
            marginalTarget.css({'right': 20});
        }
        else {
            marginalTarget.css({'right': 0});
        }
    }

    doRePadding();
    jQuery(window).resize (function(){
        doRePadding();
    });

    jQuery('.write-store').bind('click',function() {
			var classes = jQuery(this).attr('class');
			var storeUid = classes.split('store-uid-');
			setUserStore(storeUid[1]);
			checkVCardUserStore();
		});
})

// Function to change the active brand-tab of the storepages
function storeBrandTabs() {
	if(jQuery('#tab-woman').length > 0) {
		jQuery('.brands-list').hide();
		jQuery('#woman').show();
		jQuery('.tab').bind('click',function() {
			jQuery('.tab').removeClass('active');
			jQuery(this).addClass('active');
			jQuery('.brands-list').hide();
			currentId = jQuery(this).attr('id').substring(4);
			jQuery('#' + currentId).show();
		});
	}
}

// Function to save the users favorite store in a cookie
function setUserStore(storeUid) {
	 jQuery.cookie('user_store',null);
   jQuery.cookie('user_store', storeUid, { expires: 365, path: '/'});
}

// Function to get the users favorite store from cookie
function getUserStore() {
   return jQuery.cookie('user_store');
}

function checkVCardUserStore() {
	if(jQuery('.write-store').length > 0) {
		var classes = jQuery('.write-store').attr('class');
		var currentStoreUid = classes.split('store-uid-');
		var savedStoreUid = getUserStore();
		if(savedStoreUid == currentStoreUid[1]) {
			jQuery('.write-store').parent().html('<div class="av2 upper cufon">' + ll_vcard_store_saved + '</div>');
		}
		Cufon.refresh();
	}
}

// Function to get the Info-Teaser XML for Flash
function getStoreInfoTeaserXml() {
	storeUid = getUserStore();
	if(storeUid) {
		urlLength = location.href.length - location.hash.length;
		var url = location.href.substring(0,urlLength);
		return url + "?type=22&ppi_puc_store_info_teaser[store_uid]=" + storeUid + "&ppi_puc_store_info_teaser[type]=xml";
	} else {
		return false;
	}
}

function scrollToTop() {
        document.location.hash = '#toTop';
        jQuery('select.styled').css({'z-index': 0});
}

function removeModalBox() {
        jQuery('select.styled').css({'z-index': 5});
}

function setHeight() {
        var height = jQuery(document).height();
        jQuery('#nyroModalBg').css('height',height);
}

/** opens a url in a lightbox */
var openInLightbox = function (url, arguments) {
	if (typeof jQuery.fn.nyroModal == 'undefined') {
	  alert('please include fileadmin/be_user/templates/js/nyromodal/js/jquery.nyroModal-current.min.js');
	  return null;
	}

	return jQuery.nyroModalManual({url: url,
                                 bgColor: '#042047',
                                 type: 'iframe',
                                 forceType: 'iframe',
                                 modal: false,
                                 resizable: false,
                                 width: 1216,
                                 height: 727,
                                 closeButton: null,
                                 titleFromIframe: false,
                                 endFillContent: setHeight,
                                 title: false});
};

var closeLightbox = function () {
	if(parent) {
		parent.$.nyroModalRemove();
	}
	else {
		$.nyroModalRemove();
	}
}

function objectFromString(str){
  str = str.replace(/[{}]+/g, '');
  tryLog(str);
  var V={};
  var A=str.split(',');
  var L= A.length,temp;
  for(var i=0; i<L; i++){
      temp= A[i].split(':');
      V[temp[0]]=temp[1];
  }
  return V;
}

var openInPopup = function (url, conf) {
		var newConf = objectFromString(conf);
		var params = '';
        if(newConf.fullscreen) {
            params += 'width='+screen.width;
			params += ', height='+screen.height;
			params += ', top=' + (conf.top ? conf.top : 0) + ', left=' + (conf.left ? conf.left : 0);
			params += ', fullscreen=yes';
			params += ', resizable=yes';
        }
		else if(newConf.scrollbars) {
			params += 'width='+screen.width;
			params += ', height='+screen.height;
			params += ', top=' + (conf.top ? conf.top : 0) + ', left=' + (conf.left ? conf.left : 0);
			params += ', fullscreen=yes';
			params += ', resizable=yes';
			params += ', scrollbars=yes';
		}
        else {
			params += 'width='+(conf.width ? conf.width : screen.width);
			params += ', height='+ (conf.height ? conf.height : screen.height);
			params += ', resizable=yes';
        }
        newwin=window.open('/' + url,'special', params);
        if (window.focus) {newwin.focus()}
        return false;

}

var closePopup = function () {
        if(window.opener) {
                window.close();
        }
        else {
                history.back();
        }
}
function closeWindow() {
	closePopup();
}

var trackClick = function (sitename) {
        if(et_secureId && typeof window.et_eC_Wrapper == 'function') {
                et_eC_Wrapper(et_secureId, sitename);
                return true;
        }
        else {
                return false;
        }
}

function changeLength(){

i = 0;
d = document.getElementsByTagName("span");

while (element = d[i++]) {

	if (element.className == "select")
	{
      if(element.innerHTML.length>21)
 			{
				element.innerHTML=element.innerHTML.substring(0,21)+"...";
			}

		/*for(j=0;j<element.length;j++)
		{
			if(element.options[j].text.length>21)
 			{
				element.options[j].text=element.options[j].text.substring(0,21)+"...";
			}
		}*/
	}
}

}
/**
 * Diese Funktion kann fuer console.log Anweisungen verwendet werden. Damit werden dann keine Fehler erzeugt, wenn console nicht vorhanden ist
 */

function tryLog(message) {
	try {
		console.log(message);
	}
	catch (e) {
	}
}