$(document).ready(function() {
	$(".current").find("ul").show();
	$(".menu li").hover(function() {
		
		$(this).find("ul").show();
		$(this).find("ul").css({ 'z-index' : '1000'});
		$(".active").css({ 'background' : 'url(/_img/submenuactive.png) no-repeat 50% 23px'});
		
	} , function() {
		
		$(".active").css({ 'background' : 'url(/_img/submenuactive.png) no-repeat 50% 23px'});
		$(this).find("ul").hide();
		$(".current").find("ul").show();
		$(".current").find("ul").css({ 'z-index' : '999'});
	});
});



/*$(document).ready(function() {
$("a.hide").click(function(event){
event.preventDefault();
$(".contestFlashWrap").slideUp();
$("a.open").show();
}); 
});*/




function setupCalendar(ico_calendar_id,sel_days_id,sel_month_id,sel_year_id){
    $(document).ready(function(){
    var nowTime = new Date();
    var date1   = new Date(1900,nowTime.getMonth(), nowTime.getDate());
    var date2   = new Date(nowTime.getFullYear(),nowTime.getMonth(), nowTime.getDate());
    var startDate=date1.getDate()+'/'+(date1.getMonth()+1)+'/'+date1.getFullYear();
    var endDate=date2.getDate()+'/'+(date2.getMonth()+1)+'/'+date2.getFullYear();
    //alert(date1+ ' '+date2);
    // initialise the "Select date" link
    $('#'+ico_calendar_id)
    .datePicker(
    // associate the link with a date picker
    {
        createButton:false,
        startDate:startDate,
        endDate:endDate
    }
    ).bind(
        // when the link is clicked display the date picker
        'click',
        function()
        {
            //alert($(this).dpGetSelected()[0]);
            updateSelects($(this).dpGetSelected()[0]);
            $(this).dpDisplay();
            return false;
        }
        ).bind(
        // when a date is selected update the SELECTs
        'dateSelected',
        function(e, selectedDate, $td, state)
        {
            updateSelects(selectedDate);
        }
        ).bind(
        'dpClosed',
        function(e, selected)
        {
            updateSelects(selected[0]);
        }
        );

    var updateSelects = function (selectedDate)
    {

        var selectedDate = new Date(selectedDate);
        $('#'+sel_days_id+' option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
        $('#'+sel_month_id+' option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
        $('#'+sel_year_id+' option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
    }
    // listen for when the selects are changed and update the picker
    $('#'+sel_days_id+', #'+sel_month_id+', #'+sel_year_id)
    .bind(
        'change',
        function()
        {
            var d = new Date(
                $('#'+sel_year_id).val(),
                $('#'+sel_month_id).val()-1,
                $('#'+sel_days_id).val()
                );
                 
            $('#'+ico_calendar_id).dpSetSelected(d.asString());
        }
        );
    //updateSelects(date1.getTime());
    //alert('#'+sel_days_id);
    $('#'+sel_days_id).trigger('change');
});

}
function DateFromString(d){
    var p=explode('/',d);
    var date = new Date(p[2],p[1]-1,p[0]);
    return date;
}



currentImage = 0
        var timer = 0;
        function changePicture(n){
			currentImage= currentImage % pictures[n].length;
			
            $('#rotatorImage' + n).attr('src', '/imglib_thumbnails'+pictures[n][currentImage])
            currentImage ++
			
			clearTimeout(timer)
            timer = setTimeout('changePicture(' + n + ')', 750)
        }
        $(document).ready(function(){
            $(".rotator").mouseover(function(event){
				clearTimeout(timer)
                changePicture($(this).attr('id').substring(7))
            });
            $(".rotator").mouseout(function(event){
                clearTimeout(timer)
				n = $(this).attr('id').substring(7)
                currentImage = 0;
                $('#rotatorImage' + n).attr('src', '/imglib_thumbnails'+pictures[n][0])
            });
        });

function hideFlash() {
    if (document.getElementById('contestFlashWrap').style.display =='none')
    {
        document.getElementById('contestFlashWrap').style.display ='block';
        document.getElementById('hideFlashClick').style.display ='block';
        document.getElementById('openFlashClick').style.display ='none';
        $.cookie('hide_flash', null, cookie_options);
    }else{
        document.getElementById('contestFlashWrap').style.display ='none';
        document.getElementById('hideFlashClick').style.display ='none';
        document.getElementById('openFlashClick').style.display ='block';
        $.cookie('hide_flash', '1', cookie_options);
    }
}
