// JavaScript Document
jQuery(document).ready(function() {
       
	// ext: lf_ajaxcontent
	if($('div').hasClass('selfservice')){
		
		var myDate=new Date();
		
		var urlConf = {};
		urlConf['eID'] = 'lfajaxcontent';
		urlConf['unique'] = myDate.getTime();
		urlConf['handle'] = 'getCategories';
		$.getJSON(makeURL(urlConf),function(data){
			if(data['cats']){
				$('#ssselectleft').html('');
				$('#ssselectleft').append(data['cats']);
			}
		});
		

		var urlConf = {};
		urlConf['eID'] = 'lfajaxcontent';
		urlConf['unique'] = myDate.getTime();
		urlConf['handle'] = 'getEmpty';
		$.getJSON(makeURL(urlConf),function(data){
			if(data['empty']){
				$('#ssselectright').html('');
				$('#ssselectright').append(data['empty']);
			}
		});
		
		$('#ssselectleft').change(function(){
			var cat = $(this).val();
			if(cat>0){
				var urlConf = {};
				urlConf['eID'] = 'lfajaxcontent';
				urlConf['unique'] = myDate.getTime();
				urlConf['handle'] = 'getItems';
				urlConf['cat'] = cat;
				$.getJSON(makeURL(urlConf),function(data){
					if(data['items']){
						$('#ssselectright').html('');
						$('#ssselectright').append(data['items']);
					}
				});		
			}
		});
		
		$('#ssselectright').change(function(){
			var url = $(this).val();
			$('.ssfooter > p > a').attr('href',url);
		});
	}
	
	// ext: lf_visitdenmark
	if($('div').hasClass('tx-lfvisitdenmark-pi3')){
		
		$('#tx_lfvisitdenmark_pi3_accommodation_start_date').datepicker({
			showOn: "button",
			dateFormat: "dd-mm-yy",
			buttonImage: "fileadmin/images/kalender_ikon.png",
			buttonImageOnly: true,
			buttonText: "Dato"
		});
		$("#tx_lfvisitdenmark_pi3_accommodation_end_date").datepicker({
			showOn: "button",
			dateFormat: "dd-mm-yy",
			buttonImage: "fileadmin/images/kalender_ikon.png",
			buttonImageOnly: true,
			buttonText: "Dato"
		});
		$("#tx_lfvisitdenmark_pi3_experience_start_date").datepicker({
			showOn: "button",
			dateFormat: "dd-mm-yy",
			buttonImage: "fileadmin/images/kalender_ikon.png",
			buttonImageOnly: true,
			buttonText: "Dato"
		});
		$("#tx_lfvisitdenmark_pi3_experience_end_date").datepicker({
			showOn: "button",
			dateFormat: "dd-mm-yy", 
			buttonImage: "fileadmin/images/kalender_ikon.png",
			buttonImageOnly: true,
			buttonText: "Dato"
		});
		/**/
	}
	
   $( "#acordion li h3 a" ).bind( 'click', function(){
   	$('#shortcut-menu h2').hide();
   	$('#shortcut-menu .alter').show();
   });
 
    $("#acordion").each(function(){
        var acord = $(this).children("li");
   	acord.each(function(el){
 		$(this).addClass("trans" + el);
   	}); 
   });
   
   
   /*$('#accesskeys a').focus(function(){
		$('#accesskeys').attr("style","left: 10px; z-index:999;");
   });
   $('#accesskeys a').blur(function(){
		$('#accesskeys').attr("style","left: -9999px; z-index:0;");
   });*/
   
   
   // Drop-down
	$('#dropdown').appendTo('#main .inner');
		
	$('#main-nav>li').not(':first-child').each(function(i){
		$(this).hover(function(){
			var Xcord = $(this).position().left - 1;
			if($(this).hasClass('right'))
			var Xcord = $(this).position().left + $(this).width() - 525;
			$('#dropdown .dropdown-inner').hide();
			$('#dropdown .dropdown-inner').eq(i).show().css("left",Xcord);
			$(this).addClass('over');			
		}, function(){
			$('#dropdown .dropdown-inner').eq(i).hide();
			$(this).removeClass('over');	
					
		});		
	});
	$('#main-nav>li:first-child').hover(function(){
		$('#dropdown .dropdown-inner').hide();
		}, function(){
		$('#dropdown .dropdown-inner').hide();
	});
	$('#top').hover(function(){
		$('#dropdown .dropdown-inner').hide();
	});
	
	
	$('#dropdown .dropdown-inner').each(function(i){
		$(this).addClass('no-'+i);
		$(this).mouseover(function(){
			$(this).show();
			$('#main-nav>li').eq(i+1).addClass('over');
		}).mouseout(function(){
			$(this).hide();
			$('#main-nav>li').eq(i+1).removeClass('over');
		});
	});
	
        $('#main-nav>li').not(':first-child').each(function(i){
               var menu = $(this).children("ul").clone();
             	$('#dropdown .dropdown-inner .left').eq(i).append(menu);
           // console.log($('#dropdown .dropdown-inner .left').eq(i));
	
	});
	
		
	//activate facybox
	$('a[rel*=facybox]').facybox();
	
	//move gallery to the bottom of article
	$('#fwbottom').append($('.bottom-carousel'));
	
	//-----     
// Switch stylesheets starts
//-----

var c = readCookie('style');

if (c) {
    
    switchStylestyle(c);
     
    if (c == "font_11px") {
            $('#big').each(function(i) {
            $(this).attr({
                rel: "font_12px"
                });
            });
            $('#small').each(function(i) {
            $(this).attr({
                rel: "font_11px"
                });
            });
        } else if (c == "font_12px") {
            $('#big').each(function(i) {
            $(this).attr({
                rel: "font_13px"
                });
            });
            $('#small').each(function(i) {
            $(this).attr({
                rel: "font_11px"
                });
            });
        } else if (c == "font_13px") {
            $('#big').each(function(i) {
            $(this).attr({
                rel: "font_13px"
                });
            });
            $('#small').each(function(i) {
            $(this).attr({
                rel: "font_12px"
                });
            });
        }
}
    
$('#big').click(function() {

    var relatt = this.getAttribute("rel");
        
           switchStylestyle(relatt);
        
        if (relatt == "font_12px") {
        $(this).attr({
            rel: "font_13px"
            });
        }
        if (relatt == "font_13px") {    
            $('#small').attr({
            rel: "font_12px"
            });
    }
        return false;    

});     

$('#small').click(function() {

    var relatt = this.getAttribute("rel");
        
           switchStylestyle(relatt);
        
        if (relatt == "font_12px") {
        $(this).attr({
            rel: "font_11px"
            });
        }
        if (relatt == "font_11px") {    
            $('#big').attr({
            rel: "font_12px"
            });
    }
    
        return false;
});     

//-----
// Switch stylesheets ends
//-----
       
});

$(function(){
	$("#tabs").tabs();
        $("#company-tabs").tabs({
          show: function(e, ui) {
            $('.ui-carousel', ui.panel).carousel('refresh');
          }
        });

        $("#carousel-basic").carousel({
        	scroll:1,
        	visible:1
        });
        
             
       $("#acordion").accordion( {
    	active: false, 
    	header: 'h3', 
    	navigation: false, 
    	event: 'click', 
    	autoheight: false,    	
	collapsible:true
    	});
    	
    	$("#mycarousel").carousel({
       		scroll:1,
       		visible:1
    	});
    	$("#mycarousel-2").carousel({
       		scroll:1,
       		visible:1
    	});
    	$("#mycarousel-3").carousel({
       		visible:4,
       		circular:false
    	});
});

function makeURL(urlVars){
	var urlStr = '';
	if(typeof urlVars != "undefined"){ // Make the url to request including some params that the server will like
		for(key in urlVars){
			urlStr = urlStr + key + "=" + urlVars[key] + "&";
		}
	}
	// Remove trailing &
	urlStr = urlStr.substr(0,urlStr.length-1);
	urlStr = "http://" + top.location.host + top.location.pathname + "?" + encodeURI(urlStr);
	return urlStr;
}

function switchStylestyle(styleName)
{
        $('link[rel*=style][title]').each(function(i)        
        {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });
        createCookie('style', styleName, 365);
}

// Ends all jquery



// cookie functions http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days){
	if (days)	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

// cookie functions end


