// JavaScript Document
var img_array=new Array();
var img_height_array=new Array();
var current_index=0;
$(document).ready(function()
{

    //---------------------------------
        //var url_array;
		function getURLParams(){
			//var myurl = document.URL;
			//url_array=myurl.split("#");
            
			var param_array=new Array();
			var split_array=new Array();
			//if(url_array.length>1){
			var test=jQuery.url.attr("anchor");
			
			if(test!=null){
				var second_array=test.split("&");
				
				for (var j=0;j<second_array.length;j++){
					
					split_array=second_array[j].split("=");
			
					for (var i=0;i<split_array.length;i+=2){
						
						param_array[split_array[i]]=split_array[i+1];
					}
				}
				return param_array;
			}else{
				return false;
        }
			
    }
    //-------------------- archiv dropdowns
    var dropdown_id=0;
    $('.dropdown').each(function(){
        dropdown_id++;
        $(this).attr('d_id',dropdown_id);
        var sub="";
        if($(this).hasClass('sub')){
            sub="sub";
        }
        kids = $(this).children();
        kids.attr('d_id',dropdown_id);
        kids2 = kids.children();
        kids2.attr('d_id',dropdown_id);
        var inner_div='<div class="auto_dropdown_outer '+sub+'" d_id="'+dropdown_id+'" ><div class="auto_shadow '+sub+'"><div class="auto_dropdown_inner '+sub+'" d_id="'+dropdown_id+'" ></div></div><div class="auto_shadow_end '+sub+'"></div></div>';
        $('body').append(inner_div);
        $(this).clone().appendTo('.auto_dropdown_inner[d_id="'+dropdown_id+'"]');
        
        $(this).wrap("<div class='auto_dropdownholder "+sub+"'></div>");
         
         $('.auto_dropdownholder a').each(function(){
            if($(this).hasClass('selected')){
                var top=$(this).position().top-1;	
                pos="-"+top+"px";
                $(this).parents('.dropdown').css("top",pos);
            }
         });
        position=$(this).offset();
        position.left=position.left-9;
        position.top=position.top-9;
        if( position.top<0){
            position.top=5;
        }
         $('.auto_dropdown_outer[d_id="'+dropdown_id+'"]').css(position);
        
         $('.auto_dropdownholder').children().click(function(e){
            var d_id=$(this).attr("d_id");
            e.preventDefault();
            $('.auto_dropdown_outer[d_id="'+d_id+'"]').show();
            
        });
        $('.auto_dropdown_outer').hover(function(){
			//nichts
		},
		function(){
			$(this).hide();
        });
    });
    
    
    $('.auto_dropdown_outer').hide();
   
    //----------------------------------------PROGRAMM
	function dropdowns_einklappen(){
		$('.dropdownholder').each(function(){
			//$(this).attr('open','');
			$(this).children('.selection').show();					
			var id = $(this).attr('id');
			$(this).removeClass('shadow');
			$('#dropdown_end_'+id).removeClass('shadow_end');
		});
		
	}
 	$('.dropdownholder').click(function(){
			dropdowns_einklappen();	
		if($(this).attr('open')!='open'){
			
			$(this).attr('open','open');
			var id = $(this).attr('id');
			$(this).addClass('shadow');	
			$(this).children('.selection').hide();
			$('#dropdown_end_'+id).addClass('shadow_end');	
		}else{
				
			$(this).attr('open','');
			
			}
	});
	$('.dropdownholder').hover(function(){
			//nichts
		},
		function(){
			$(this).attr('open','');
			dropdowns_einklappen();
	});
	$('.nav_dropdown_inner li').click(function(){
		p=$(this).parent();
		unselect_options(p);
		
		
		$(this).children('a').each(function(){
						$(this).attr('selected','selected');	
						$(this).addClass('selected');
						set_selection(p,$(this).text(),$(this).attr('key'));
		});
		
		dropdowns_einklappen();
		
	});
	function unselect_options(p){
		p.children('li').each(function(){
					//alert("test");
					$(this).children('a').each(function(){
						$(this).attr('selected','');	
						$(this).removeClass('selected');
					});
		});
		
	}
	function set_selection(p,the_text, key){
		p.parent().children('.selection').each(function(){
					$(this).text(the_text);
					handle_dropdown_select($(this).attr('index'),key);
		});
		
	}
	current_programmclass='programm_dateview';
	var current_view='date';
	var other_view='content';
	var current_key=new Array();
	current_key['city']='all';
	current_key['category']='all';
	
	function handle_dropdown_select(index,key){
		/*if(event_only){
            current_programmclass='programm_contentview';
        }*/
		if(index=='view'){
			//alert(index+" - "+key);
				if(key=='date'){
					current_view='date';
					other_view='content';
					current_programmclass='programm_dateview';
					//$('.programm_dateview').show();
					$('.programm_contentview').hide();
					handle_dropdown_select('city',current_key['city']);
					handle_dropdown_select('category',current_key['category']);
				}else{
					current_view='content';
					other_view='date';
					current_programmclass='programm_contentview';
					$('.programm_dateview').hide();
					//$('.programm_contentview').show();
					handle_dropdown_select('city',current_key['city']);
					handle_dropdown_select('category',current_key['category']);
				}
		}
		if(index=='city'||index=='category'){
			current_key[index]=key;
			show_current_programm_articles();
			$('.'+current_programmclass).each(function(){
					if(!$(this).hasClass(current_key['city']) || !$(this).hasClass(current_key['category']))	{ 
						$(this).hide();
					}									   
			});
		}
		
		
	}
	
	function hide_current_programm_articles(){
		$('.'+current_programmclass).hide();
	}
	
	function show_current_programm_articles(){
		$('.'+current_programmclass).show();
	}
	var urlparam= getURLParams();
	
	if(urlparam["open"]!=undefined){
		$('.programm_title[content_id="'+urlparam["open"]+'"]').each(function(){
            
			hide_pdate_contents();
            $(this).addClass('open');
			var relid=$(this).attr('relid');
			var img_relid=$(this).attr('img_relid');
			var id=$(this).attr('dateid');
            var unique=$(this).attr('unique');
			var content_img=$('#'+img_relid).html();
			var content=$('#'+relid).html();
			$('#ticket_'+id+"_"+unique).show();
            $('#pdate_img_'+id+"_"+unique).html(content_img);
			$('#pdate_img_'+id+"_"+unique).slideDown();
			
			
			$(this).parent().children(".pdate_text_holder").html(content);
            $(this).parent().children(".pdate_text_holder").slideDown();
            //alert('test');
            var pos=$(this).position().top;	
            //document.body.scrollTop=pos;
            $("body").scrollTo(pos,{duration:1});
            /*$(document).scrollTo(pos,800);*/
            $(this).parent().children(".pdate_text_holder").show();
            //alert('nachher');	
            
            						
		});
	}
    
    
	$('.programm_title').click(function(){
            
            
            
            if($(this).hasClass('open')){
                hide_pdate_contents();
            }else{
                
                hide_pdate_contents();
                var relid=$(this).attr('relid');
                var img_relid=$(this).attr('img_relid');
                var id=$(this).attr('dateid');
                var unique=$(this).attr('unique');
            
                var content_img=$('#'+img_relid).html();
                var content=$('#'+relid).html();
                $(this).addClass('open');
                $('#ticket_'+id+"_"+unique).slideDown();
                $('#pdate_img_'+id+"_"+unique).html(content_img);
                $('#pdate_img_'+id+"_"+unique).slideDown();
                
                $(this).parent().children(".pdate_text_holder").html(content);	
                $(this).parent().children(".pdate_text_holder").slideDown('fast',function(){
                    /*var pos=$(this).position().top;	
                    //document.body.scrollTop=pos;
                    $("body").scrollTo(pos,{duration:300});*/
            
                });
            }
			
            
										
	});
	function hide_pdate_contents(){
            $('.programm_title').removeClass('open');
			$('.pdate_text_holder').slideUp();
			$('.pdate_img_holder').slideUp();
			$('.pdate_ticket').slideUp();
	}
    //--------------------- img rollover
    
    $('.img_rollover').hover(
        function(){
            $(this).children('.hover_img').show();
            $(this).children('.main_img').hide();
        },
        function(){
            $(this).children('.main_img').show();
            $(this).children('.hover_img').hide();
    
    });
    
    //----------------------------------------IMGCONTAINER
    $('#close_img').click(function(){
        $('#img_container').hide();
    
    });
    $('#next_img').hover(
        function(){
            $('#next_arrow_over').show();
            $('#next_arrow').hide();
        },
        function(){
            $('#next_arrow_over').hide();
            $('#next_arrow').show();
    });
    $('#prev_img').hover(
        function(){
            $('#prev_arrow_over').show();
            $('#prev_arrow').hide();
        },
        function(){
            $('#prev_arrow_over').hide();
            $('#prev_arrow').show();
    });
    $('#next_img').click(function(){
        
        var next_index= parseInt(current_index)+1;
        
        if(next_index<img_array.length){
            //alert(next_index);
            current_index=next_index;
            $('#img_holder').css('min-height',img_height_array[next_index]+"px");
            $('#img_holder').html(img_array[next_index]);
            check_img_nav();
        }
    });
    $('#prev_img').click(function(){
       
        var prev_index=parseInt(current_index)-1;
        
        if(prev_index>=0){
            current_index=prev_index;
            $('#img_holder').css('min-height',img_height_array[prev_index]+"px");
            $('#img_holder').html(img_array[prev_index]);
        }
        check_img_nav();
    });
    function check_img_nav(){
        $('#prev_img').show();
        $('#next_img').show();
        $('#next_img_off').hide();
        $('#prev_img_off').hide();
        if(current_index==0){
            $('#prev_img').hide();
            $('#prev_img_off').show();
        }
        if(current_index==(img_array.length-1)){
            $('#next_img').hide();
            $('#next_img_off').show();
        }
    
    }
    
		


});
var current_programmclass='programm_dateview';
function setContentProgrammClass(){
        //alert("hallo");
        current_programmclass='programm_contentview';
    }
$(document).ready(function()
{
 
         
});