var helper = {

    Version: '0.1',
    extKey: 'sfpHelper',

    hideElements : function (boxId, tagName) {

        hideMe = new Array();
        hideMe = $A($(boxId).getElementsByTagName(tagName)).each(function(e) {
		
		if (e.style.visibility == '' || e.style.visibility == 'visible') {
			e.style.visibility = 'hidden';  
		} else {
			e.style.visibility = 'visible';  	
		}                 
           
        });
    },

    preloadImages : function(imglist) {
        var imgs = new Array();
        var count;
        if (document.images) {
            for (count=0; count<imglist.length; count++) {
                imgs[count]=new Image(); imgs[count].src=imglist[count];
            }
        }
    },

    sfHover : function(idList, tagList) {
	
	var count;
	
	for (count=0; count<idList.length; count++) {
		if ($(idList[count])) {
			var sfEls = $(idList[count]).getElementsByTagName(tagList[count]);
			
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
				    this.className+=' sfhover';
				}
				sfEls[i].onmouseout=function() {
				    this.className=this.className.replace(new RegExp(' sfhover\\b'), '');
				}
			}
		}
	}
	
    },

    random : function(imgs) {
        var imgsNum = 0;

        imgs.each(function(imgs){
            imgsNum ++
        });

        var imgSelect = Math.round(Math.random()*(imgsNum-1));
        var bgImage = imgs[imgSelect];

        $('header').setStyle({
            backgroundImage: 'url('+bgImage+')'
        });
    },


    //showloading
    loading : function (boxId, action) {

        var ajaxLoader = $(boxId);

        if (ajaxLoader) {

             if (action == 'start') {
                Effect.Appear (ajaxLoader);
             } else {
               ajaxLoader.hide();
            }

        }
    }

}


var newsletterSubscribe = {
	
	init : function () {
		
                if($('tx-sremailsubscribe-pi1-module_sys_dmail_category')) {
                        var subscribeOption = $A($('tx-sremailsubscribe-pi1-module_sys_dmail_category'));		
                        
                        subscribeOption.each(function(e) {
                                
                                var selectedItems = new Array();
                                
                                //german
                                switch (JSFE['L']) {
                                        
                                        //german
                                        case 0:
                                                selectedItems = [1,40];	
                                        break
                                        
                                        //french
                                        case 1:
                                                selectedItems = [26];
                                        break
                                
                                        //italien
                                        case 2:
                                                selectedItems = [39];
                                        break				
                                        
                                }	
                                        
                                if (e.value) {
                                                
                                        selectedItems.each(function(ee) {
                                                
                                                if(e.value == ee) {
                                                        e.selected = 'selected';							
                                                }
                                        });
                                        
                                } else {
                                        e.selected = '';
                                }
                        });
                        
                
                        var staticCountries = document.getElementsByName('FE[tt_address][static_info_country]')[0];
                        staticCountries.id = 'FE-tt_address-static_info_country';
                        
                        var staticCountriesOption = $A($('FE-tt_address-static_info_country'));
                        
                        staticCountriesOption.each(function(e) {
                                if(e.value == 'CHE') {
                                        e.selected = 'selected';
                                }
                        });
                }
		
	}
	
}


