// JavaScript Document

/*
// €
// --------------------------------------------------------------------------
// jQuery.custom.js by orangepointsolutions Ltd., www.orangepointsolutions.de
// --------------------------------------------------------------------------
*/

$(document).ready(function() {

/*
// --------------------------------------------------------------------------
// general settings
// --------------------------------------------------------------------------
*/

var ma = '@';
var md = 'aranxoo';
var mt = 'de';

var isIE6 = false;
if ( $.browser.msie && jQuery.browser.version == '6.0' ) { isIE6 = true; }

// $('input:text').setMask(); // mask input form fields using meiomask

$("#back2top a#b2top").click( function() { $.scrollTo( 0, 400 ); });

// toggle site credits

$('#footer_sitecredits').click( function() {
	credits = $('#footer_sitecredits span');
	if ( credits.is(":visible") ) {
		credits.animate({ opacity: 'hide' }, 'normal');
	} else {
		credits.animate({ opacity: 'show' }, 'normal');
	}
});

// mail

$("span.myml[alt*='info']").append( 'info'+ma+md+'.'+mt );
$("span.mymllnk[alt*='info']").append( '<a href="mailto:'+'info'+ma+md+'.'+mt+'">info'+ma+md+'.'+mt+'</a>' );
$("span.mymllnk[alt*='widerruf']").append( '<a href="mailto:'+'widerruf'+ma+md+'.'+mt+'">widerruf'+ma+md+'.'+mt+'</a>' );
$("span.mymllnk[alt*='upload']").append( '<a href="mailto:'+'upload'+ma+md+'.'+mt+'">upload'+ma+md+'.'+mt+'</a>' );


/*
// --------------------------------------------------------------------------
// formfield highlighting
// --------------------------------------------------------------------------
*/

$("input.textfield").hover( function() { $(this).addClass("hover"); });
$("input.textfield").mouseout( function() { $(this).not(".has_focus").removeClass("hover"); });
$("input.textfield").focus( function() { $(this).addClass("hover").addClass("has_focus"); });
$("input.textfield").blur( function() { $(this).removeClass("hover").removeClass("has_focus"); });
$("textarea").hover( function() { $(this).addClass("hover"); });
$("textarea").mouseout( function() { $(this).not(".has_focus").removeClass("hover"); });
$("textarea").focus( function() { $(this).addClass("hover").addClass("has_focus"); });
$("textarea").blur( function() { $(this).removeClass("hover").removeClass("has_focus"); });

/*
// --------------------------------------------------------------------------
// company
// --------------------------------------------------------------------------
*/

$('.r1').mouseover(function() { $(this).parent().children(".rating_text").text('nicht zu empfehlen'); });
$('.r2').mouseover(function() { $(this).parent().children(".rating_text").text('habe mehr erwartet'); });
$('.r3').mouseover(function() { $(this).parent().children(".rating_text").text('ist ok'); });
$('.r4').mouseover(function() { $(this).parent().children(".rating_text").text('bin zufrieden'); });
$('.r5').mouseover(function() { $(this).parent().children(".rating_text").text('bin sehr zufrieden'); });
$('.rating').mouseleave(function() { $('.rating_text').text(''); });

// -- end of company --


/*
// --------------------------------------------------------------------------
// oo box
// --------------------------------------------------------------------------
*/

var oo_box_visible = true;

function oo_box_hide() {
		$('#oo_box > *').animate({ opacity: 'hide' }, 'fast', function() {
			$('#oo_box').animate({ height: 'hide', opacity: 'hide' }, 'normal');
			$('#oo_slimbox').animate({ height: 'show', opacity: 'show' }, 'normal');
			$('#oo_box_close').animate({ right: '0px' }, 'normal');
			$.cookie('oo', 0, null );
		});
		oo_box_visible = false;
}

function oo_box_quick_hide() {
		$('#oo_box > *').hide();
		$('#oo_box').hide();
		$('#oo_slimbox').show();
		$('#oo_box_close').css("right", "0px" );

		$.cookie('oo', 0, null );
		oo_box_visible = false;
}

$('#oo_box_close').click(function() {
	if ( oo_box_visible ) {
		oo_box_hide();
	} else {
		$('#oo_box').animate({ height: 'show', opacity: 'show' }, 'normal', function() {
			$('#oo_box > *').animate({ opacity: 'show' }, 'fast' );
			$.cookie('oo', 1, null );
		});
		$('#oo_slimbox').animate({ height: 'hide', opacity: 'hide' }, 'normal');
		if ( !isIE6 ) { 
			$(this).animate({ right: '100px' }, 'normal');
		}
		oo_box_visible = true;
	}
});

// login box

$('#login_box #id').focus(function() { 
	old_id = $(this).val(); 
	if ( old_id == 'Benutzername' ) { $(this).val(''); }
});

$('#login_box #pw').focus(function() { old_pw = $(this).val(); $(this).val(''); });

$('#login_box #id').blur(function() { if ($(this).val() == '' ) { $(this).val('Benutzername'); } });
$('#login_box #pw').blur(function() { if ($(this).val() == '' ) { $(this).val(old_pw); } });

// register_selection box

var oo_box_register_selection_visible = false;

$('#register_box #btn_register').click(function() {
	if ( oo_box_register_selection_visible ) {
		$('#register_selection_box').animate({ opacity: 'hide' }, 'fast', function() {
			$('#register_teaser_text').animate({ opacity: 'show' }, 'fast');
		});
		oo_box_register_selection_visible = false;
	} else {
		$('#register_teaser_text').animate({ opacity: 'hide' }, 'fast', function() {
			$('#register_selection_box').animate({ opacity: 'show' }, 'fast');
		});
		oo_box_register_selection_visible = true;
	}
});

// initialize

if ( $.cookie('oo') != 1 ) {
	oo_box_quick_hide();
}

// -- end of oo box --


/*
// --------------------------------------------------------------------------
// headlines
// --------------------------------------------------------------------------
*/

// content
/*
$("#column_left h1:contains('Veranstaltung planen')").replaceWith('<img class="h1_content" src="../images/veranstaltung-planen.gif" alt="">');
$("#column_left h1:contains('Aktuelle Veranstaltungen')").replaceWith('<img class="h1_content" src="../images/aktuelle-veranstaltungen-liste.gif" alt="">');
$("#column_left h1:contains('Nutzungsbedingungen')").replaceWith('<img class="h1_content" src="../images/nutzungsbedingungen.gif" alt="">');
$("#column_left h1:contains('AGB')").replaceWith('<img class="h1_content" src="../images/agb.gif" alt="">');
$("#column_left h1:contains('Datenschutzhinweise')").replaceWith('<img class="h1_content" src="../images/datenschutz.gif" alt="">');
*/
// boxes

$("#column_right h1:contains('Support')").replaceWith('<img class="h1_box_left" src="images/support.gif" alt="">');
$("#column_right h1:contains('Merkzettel')").replaceWith('<img class="h1_box_left" src="images/merkzettel.gif" alt="">');
$("#column_right h1:contains('Ich möchte')").replaceWith('<img class="h1_box" src="images/ich-moechte.gif" alt="">');
$("#column_right h1:contains('Aktuelle Veranstaltungen')").replaceWith('<img class="h1_box" src="images/aktuelle-veranstaltungen.gif" alt="">');
$("#column_right h1:contains('DJs aufgepasst')").replaceWith('<img class="h1_box" src="images/djs-aufgepasst.gif" alt="">');

// -- end of headlines --


/*
// --------------------------------------------------------------------------
// Default Layout
// --------------------------------------------------------------------------
*/

// box layout

if ( isIE6 == false ) {
	
	if ( js_layout == 'default_layout' ) { 
		$("div.default_layout .main_container").box();
	}
	if ( js_layout == 'veranstaltung_planen' ) { 
		$("div.default_layout .main_container").box();
	}
	if ( js_page == 'provider_details' ) { 
		$("#image_gallery").box();
		$("#image_gallery img")
			.css( 'opacity', '0.9' )
			.hover(
				function() { 
					$(this).animate({ opacity: '0.5' }, 'fast', function() { $(this).animate({ opacity: '1.0' }, 'slow'); } );
				}, 
				function() { 
					$(this).animate({ opacity: '0.9' }, 'fast');
				} 
			);
		$("#video_gallery").box();
	}
	if ( js_page == 'provider_feedback' ) { 
		$(".feedback").box();
	}
	if ( js_page == 'provider_directory' ) { 
		$(".top_anbieter").box();
	}

} // end of isIE6

// table coloring
$("div.default_layout table.events tr:has(td):even").addClass("odd");
// all but headline
$("div.default_layout table.events tr:has(td)").hover( 
	function() { 
		$(this).addClass("hover");
	}, 
	function() { 
		$(this).removeClass("hover");
	} 
);

// -- end of Default Layout --


/*
// --------------------------------------------------------------------------
// Aktuelle Veranstaltungen / Search results (content)
// --------------------------------------------------------------------------
*/

// init
$("#search_result_container > div.event").children(".right").children(".btn").hide();

// hover
$("#search_result_container > div.event").hover(function() {
	$(this).children(".right").children(".btn").show();
	$(this).addClass("search_result_highlight");
});

// mouseleave
$("#search_result_container > div.event").bind("mouseleave",function(){ 
	$(this).children(".right").children(".btn").hide();
	$(this).removeClass("search_result_highlight");
});

// click
$("#search_result_container > div.event .btn_eventdetails").click( function() {
	$(this).parent().parent().children(".eventdetails").toggle();
	$(this).toggleClass("btn_eventdetails_active");
});

// -- end of Aktuelle Veranstaltungen / search results --


/*
// --------------------------------------------------------------------------
// my aranxoo
// --------------------------------------------------------------------------
*/

// init
$("#event_details.my_aranxoo .eventdetails a.btn_eventdetails").hide();
$("#event_details.my_aranxoo .eventdetails a.btn_eventdetails_edit").hide();
$("#event_details.my_aranxoo .eventdetails a.btn_lock").hide();

// hover
$("#event_details.my_aranxoo .eventdetails .category").hover(function() {
	$(this).children("a.btn_eventdetails").show();
	$(this).children("a.btn_eventdetails_edit").show();
	$(this).children("a.btn_lock").show();
//	$(this).addClass("search_result_highlight");
});

// mouseleave
$("#event_details.my_aranxoo .eventdetails .category").bind("mouseleave",function(){ 
	$(this).children("a.btn_eventdetails").hide();
	$(this).children("a.btn_eventdetails_edit").hide();
	$(this).children("a.btn_lock").hide();
//	$(this).removeClass("search_result_highlight");
});

// click on details
$("#event_details.my_aranxoo .eventdetails .category a.btn_eventdetails").click( function() {
	$(this).next("div.details_box").toggle();
	$(this).next("div.details_box:visible").css("border", "1px solid #fff"); // dummy function
	$(this).toggleClass("btn_eventdetails_active");
});

// click on details edit (proposal scope)
$("#event_details.my_aranxoo .eventdetails .category a.btn_eventdetails_edit").click( function() {
	$(this).next().next().next().next().next(".form_proposalscope_part").toggle();
	$(this).next().next().next().next().next(".form_proposalscope_part:visible").show(); // dummy function
});

// click on lock category
$("#event_details.my_aranxoo .eventdetails .category a.btn_lock").click( function() {
	$(this).next().next().next().next().next().next().next().next().next(".form_lock_part").toggle();
	$(this).next().next().next().next().next().next().next().next().next(".form_lock_part:visible").show(); // dummy function
});

// proposal details
$(".status_hint:has(p)").show();

// -- end of my aranxoo --


/*
// --------------------------------------------------------------------------
// Event Details
// --------------------------------------------------------------------------
*/

// toggle proposal forms

$('div#event_details img#[id^="btn_proposal"]').click( function() {
	form = $(this).parent().children('form[id^="form_proposal"]');
	if ( form.is(":visible") ) {
		form.animate({ opacity: 'hide' }, 'normal'); // form
		form.prev().animate({ opacity: 'hide' }, 'normal'); // response container near form
	} else {
		form.animate({ height: 'show', opacity: 'show' }, 'normal');
	}
});

// also used for other forms
$('div#event_details p#[id^="close_form"]').click( function() {
	form = 	$(this).parent('form.[class^="form_"]');
	form.animate({ opacity: 'hide' }, 'normal');
	form.prev().animate({ opacity: 'hide' }, 'normal');
	hide_proposal_button( form.parent() );
});

// calculate provision
// complete
$('div#event_details input#text_preis').keyup( function() {
	var provision = parseFloat( $(this).val().replace(".", "").replace(",", "")/100 );
	var p1 = provision; 
	var p2 = parseFloat(Math.round((p1 * 0.049)*100)/100);
	$(this).next().next("p").html( 'Provision: ' + p2.toFixed(2).replace(".", ",") + ' €' );
});
// part
$('div#event_details input#[id^="text_preis_"]').keyup( function() {
	var provision = parseFloat( $(this).val().replace(".", "").replace(",", "")/100 );
	var p1 = provision; 
	var p2 = parseFloat(Math.round((p1 * 0.049)*100)/100);
	$(this).next().next("p").html( 'Provision: ' + p2.toFixed(2).replace(".", ",") + ' €' );
});

// show and hide category proposal buttons

function hide_proposal_button ( category ) {
	category.children("img.btn_proposal_part").animate({ opacity: '0.10' }, 'fast');
	category.children("p.proposal_part_hint").animate({ opacity: '0.10' }, 'fast');
}

$("div.eventdetails > div.category > img.btn_proposal_part").animate({ opacity: '0.10' }, 'fast');
$("div.eventdetails > div.category > p.proposal_part_hint").animate({ opacity: '0.10' }, 'fast');

$("div.eventdetails > div.category").hover(function() {
	$(this).children("img.btn_proposal_part").animate({ opacity: '1' }, 'fast');
	$(this).children("p.proposal_part_hint").animate({ opacity: '1' }, 'fast');
});

$("div.eventdetails > div.category").bind("mouseleave",function(){ 
	form = $(this).children('form[id^="form_proposal"]');
	if ( !form.is(":visible") ) {
		hide_proposal_button( $(this) );
	}
});


// -- end of Event Details --




    // handle internal links
	
    $(".internal_link").mouseover(function(){ // mouseover on internal link handler
		$(this).toggleClass('underline');
	});
									
    $(".internal_link").mouseout(function(){ // mouseover on internal link handler
		$(this).toggleClass('underline');
	});
	
	
    $("#link_imprint").click(function(){ // click on imprint link handler
		// switch content
		$("#bottom_standard").fadeOut("fast", function() {
		    $("#imprint").fadeIn("slow"); 
		});
    });
	
    $("#link_back").click(function(){ // click on back link handler
		// switch content
		$("#imprint").fadeOut("fast", function() {
		    $("#bottom_standard").fadeIn("slow"); 
		});
    });
	
    $("#link_privacy").click(function(){ // click on back to imprint link handler
		// switch content
		$("#imprint").fadeOut("fast", function() {
		    $("#privacy").fadeIn("slow"); 
		});
    });
	
    $("#link_back_to_imprint").click(function(){ // click on back to imprint link handler
		// switch content
		$("#privacy").fadeOut("fast", function() {
		    $("#imprint").fadeIn("slow"); 
		});
    });
	
	// -----
	// initial page preparation
	// -----
	
	// fade in shapes
	$("#imprint").hide();
	$("#privacy").hide();
	$("#logo").hide();
	$("#logo").fadeIn(1200);
	
	// detect flash
	/* -----
	if ( GetSwfVer() == -1 ) {
		$("#bg_container").css("background", "url(images/bg_splash_sea.JPG) no-repeat top right");
	}
	----- */

	
    // in memory of IE6 set some elements to document height
/*	$("#bg_container").css( "height", $(document).height()+"px" );
	$("#bg_pattern").css( "height", $(document).height()+"px" );
	$("#tagline_container").css( "height", $(document).height()+"px" );
	$("#content_container").css( "height", $(document).height()+"px" );
*/



});



/*
// --------------------------------------------------------------------------
// misc functions
// --------------------------------------------------------------------------
*/

function nl2br (str, is_xhtml) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson / Onno Marsman / Atli Þór 
    // +   bugfixed by: Onno Marsman / Kevin van Zonneveld
    // +      input by: Brett Zamir (http://brett-zamir.me)
 
    var breakTag = '';
 
    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }
 
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}

function budget2int (budget) {
	var text = budget;
	text = text.replace(/[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ€$.]/g , '');
	return ( parseInt(text) );
}

// --- end of jQuery.custom.js ---

