$(document).ready(function() {

	windowResize();
	tooltip();
	
	//Effect for Main Navigation
	$("#header li a").mouseover(function() {
    	$(this).animate({ fontSize: "1.3em", marginTop: "-0.3em" }, 150 );
  	});
  	$("#header li a").mouseout(function() {
    	$(this).animate({ fontSize: "1em", marginTop: "0em" }, 150 );
  	});
});
window.onresize = windowResize;
function windowResize(){
	var windowWidth = window.innerWidth;
	if (!$.browser.mozilla) {
		windowWidth = document.documentElement.clientWidth;
	}
	if (windowWidth < 1250) {		
		$('#main').css({
			'width': '970px'
		});
		$('.gallery-slider-wrapper').css({
			'width': '970px'
		});
		$('.gallery-viewport').css({
			'width': '970px'
		});
	} else {
		var mainWidth = windowWidth - 270;
		var galleryViewportWidth = windowWidth - 401;
		$('#main').css({
			'width': mainWidth + 'px'
		});
		$('.gallery-slider-wrapper').css({
			'width': mainWidth + 'px'
		});
		$('.gallery-viewport').css({
			'width': galleryViewportWidth + 'px'
		});
	}
	$('.gallery-slider-wrapper-teaser').css({
		'width': '900px'
	});
	$('.gallery-viewport-teaser').css({
		'width': '838px'
	});
}

function contentloader(url) {
    // Dialog
	$("#lightbox-container").load(url);
	$('#lightbox-container').dialog({
		modal: true, 
		width: 650, 
		title: url,
		open: function(event, ui) {
			$("#lightbox-container").css( 'display' , 'none' );
			$("#lightbox-container").fadeIn(500);
		},
		close: function(event, ui) {
			$("#lightbox-container").fadeOut(500);
			$('#lightbox-container').dialog('destroy');
			$("#lightbox-container").css( 'display' , 'none' );
		}
	});
}

function searchFunctions() {
	$('#searchword').click(function(){
		$('#searchword').attr('value', '');
	});
}
function tooltip() {
	$('#main a.image-item').tooltip( {
		track: true,
		delay: 0,
		showURL: false,
		fade: 250,
		top: -250,
  		bodyHandler: function() { 
			return $('<div style="width: ' + $(this).attr("cmdb:preview_width") + 'px;"/>').html( '<img src="' + $(this).attr("cmdb:preview") + '"><br>' + $(this).attr("cmdb:caption")  + '<br><i>Archiv-ID: ' + $(this).attr("cmdb:mid") + '</i>' );
  		}
	});	
}

function login(targetURL, baseURL) {
        var userid = $("#login-username").attr('value');
        var passwd = $("#login-password").attr('value');
        $.ajax({
                type: 'POST',
                url: '/CMDB/',
                data: { action: '502', username: userid, password: passwd },
                dataType: 'xml',
                success: function(res) {
                        var status = $('authenticated', res).text();
                        if (status == 1) {
                                if (targetURL.indexOf("action=204") == -1) {
                                        window.location.href = targetURL;
                                } else {
                                        window.location.href = baseURL;
                                }
                        } else {
                                $('#login-status-msg').text('Benutzername/Kennwort ist falsch!');
                                $('#login-status-box').show();
                        }
                }
        });
}

function addToBasket(mid) {
	$.ajax({
		type: 'POST',
  		url: '/CMDB/',
  		data: { action: '506', id: mid },
  		dataType: 'xml',
  		success: function(res) {
			var success = $(res).find('success').text();
			if (success == 'true') {
				$.jGrowl("Bild wurde hinzugefügt", {
					closer: false,
					life: 1500
				});
  			}
		}
	});
}

