/* IDENTIFY START */
var identifier = 0;

/* DOM READY */
(function($) {
    $(function() {
        /* initialize tb language */
        /*if(!!tbLanguage) tb_language(tbLanguage);
        if(!!tbWindowWidth) tb_windowWidth(tbWindowWidth);
        
        /* external links */
        $('a[rel="external"]').attr('target', '_blank');
        
        /* popup links */
        $('a[rel="popup"]').click(function() {
            var name = $(this).attr('id');
            if(!name) {
                name = 'identifier_' + ++identifier;
                $(this).attr('id', name);
            }
            var width   = height = 650,
                top     = left   = 0,
                percent = 80;
            if(!!screen.width) {
                width = Math.ceil((screen.width / 100) * percent);
                left  = Math.ceil((screen.width - width) / 2);
            }
            if(!!screen.height) {
                height = Math.ceil((screen.height / 100) * percent); 
                top    = Math.ceil((screen.height - height) / 2);
            }
            window.open($(this).attr('href'), name, 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes');
            return false;
        });
        
        /* download links */
        $('a[rel="download"]').click(function() {
            var file = $(this).attr('href'),
                ext  = file.split('.').pop().toLowerCase();
            if($.inArray(ext, ['gif', 'png', 'jpg', 'jpeg', 'bmp']) > -1) {
                window.open(file);
                return false;
            }
        });
        
        $('.catGroup .catGroupName').click(function(){        	
        	var parent =$(this).parent(); 
        	if(parent.hasClass('folded')){        		
        		parent.removeClass('folded');
        		parent.addClass('unfolded');
        		$('.catGroupCategories', parent).slideDown();
        	}else{		
        		parent.addClass('folded');
        		parent.removeClass('unfolded');
        		$('.catGroupCategories', parent).slideUp();
        	}        		
        });
        
        var BackLinks = $('#contentContainer').children('.detailBack').size();
        if(BackLinks > 1){
        	BackLinks = BackLinks-1;
        	$('#contentContainer').children('.detailBack').each(function(i, e){
        		if(i < BackLinks){
        			$(e).remove();
        		}
        	});
        }
        $('#allphotoslink').click(function(){
        	var parent = $('#catPhotos');
        	if(parent.hasClass('folded')){        		
        		parent.removeClass('folded');
        		parent.addClass('unfolded');
        		$('.catGroupCategories', parent).slideDown();
        	}  
        	window.location = '#photos';
        	return false;
        });
    	$('.eventSearchOptions #datePicker').bind('click',function(){
    		if($('.eventSearchOptions #fromNDTRC').val() != ''){
    			$('.eventSearchOptions #datetype').val('custom');
    			
    		}
    		return false;
    	});
    });
})(jQuery);
