/**
 * @author
 * @projectDescription
 * @blog http://blog.alexandremagno.net
 * @version 1.0
 * @param params
 * @param header
 * @example
 * @browser Firefox 2.0+ IE6
 * @return jQuery
 *
 *
 */



jQuery.fn.ssl = function(params) {

		var options = {

			//mode : 'urlreplace',

			//_modeListe:['https','urlreplace','urlreplacecookie'],

			host_no_ssl : 'http://www.abbott-diabetes-care.de',
            host_ssl :  'https://www.abbott-diabetes-care.de',
            sslSites : []

		}
		var op = jQuery.extend(options, params);
		var $el = $(this);

		return this.each(function(){
			
			//console.debug(this.href);
			
			
			/*
			switch(this.tagName){
				case 'A':
					var url = this.href;
				break;
				case 'FORM':
					var url = this.action;
				break;
				default:
					console.debug(this.tagName);
				break;
				
			}
			*/
			
			var url = this.href;
			
			
			
			//url = url.replace(/([^\/]*\/){4}([^\/]*)(.*)/,"$2");
			
			//console.debug(url);
			var urlToken = url.split("/");
			
			
			var file = urlToken[urlToken.length-1];
			
			
			var protokoll = urlToken[0];
			
			
			
			
			
			
			if(protokoll == 'https:'){
				if( !IsSSLFile(file)){
            		this.href = UnbuildSSLurl(urlToken);
            	}
			}else if(protokoll == 'http:'){
				if( IsSSLFile(file)){
            		this.href = BuildSSLurl(urlToken);
            	}
			}
			
			
			/*
			
			//console.debug(file);
			
			if(url.lastIndexOf(op.host_ssl)==0){
				var check = false;
				for(var a =0;a<op.sslSites.length;a++){
                    if(op.sslSites[a]==file ){
                        check = true;
                        //break;                        
                    }                    
                }
                if(check){
                	this.href = UnbuildSSLurl(urlToken);
                    //break;   
                }
			
			}else{                
                for(var a =0;a<op.sslSites.length;a++){
                    if(op.sslSites[a]==file ){
                        this.href = BuildSSLurl(urlToken);
                       // break;                        
                    }
                    
                }
            }
            
            
            if( IsSSLFile(file)){
            	this.href = BuildSSLurl(urlToken);
            }
            */
            
            function IsSSLFile(file){
            	for(var a =0;a<op.sslSites.length;a++){
                    if(op.sslSites[a]==file ){
                    	return true;
                    }
            	}
            	return false;
            }
            
            
            function BuildSSLurl(urlToken){            	
            	var url = op.host_ssl;
            	for(var a =3;a<urlToken.length;a++){
            		url = url + '/' + urlToken[a];
            	}            	
            	return url;
            }
            function UnbuildSSLurl(urlToken){            	
            	var url = op.host_no_ssl;
            	for(var a =3;a<urlToken.length;a++){
            		url = url + '/' + urlToken[a];
            	}            	
            	return url;
            }
			
		});
		
		

};
