$(document).ready(function(){

});

function showSlidesWithErrors() {
    $('div.ofraccount div.slidecontent span.trigger').each(function(){
        if( $(this).parent().parent().next('.receiver').find('.validationhint').length > 0 ) {
            $(this).trigger('click');
        }
    });
}

function makeSlides() {
    $('div.ofraccount div.slidecontent .receiver').hide();
    $('div.ofraccount div.slidecontent span.trigger').each(function() {
        if($(this).parent().parent().next('.receiver').html() != null){
            $(this).toggle(
                function(){
                    $(this).parent().parent().next('.receiver').slideDown('fast');
                    $(this).removeClass('down').addClass('up');
                    var name = $(this).attr('id');
                    if((name.lastIndexOf('_') != (name.length-1)) && (name != '') && (name != null) && isDefined(name)) {
                        setCookie(name,'open',30);
                    }
                    
                },
                function(){
                    $(this).parent().parent().next('.receiver').slideUp('fast');
                    $(this).removeClass('up').addClass('down');
                    var name = $(this).attr('id');
                    if((name.lastIndexOf('_') != (name.length-1)) && (name != '') && (name != null) && isDefined(name)) {
                        //setCookie(name,'closed',30);
                        deleteCookie(name);
                    }
                    
                }
                ).removeClass('deadend').addClass('down');
        }
    });
    $('div.ofraccount div.slidecontent .trigger.first').trigger('click').removeClass('first');
}

function slideToCurrentImage(){
    if( $('div.imagewrapper td.scrollTo').length > 0 ) {
        $('div.imagewrapper td.scrollTo').each(function() {
            try{
                var topparent = $(this).parents('table').offset();
                var top = $(this).offset();
                var scrollvalue = top.top - topparent.top;
                $(this).parents('div.imagewrapper').scrollTop(scrollvalue);
            } catch(e) {
                
            }
            
        });
    }
}

function restoreSlides(prefix) {
    var cookie_pairs = document.cookie.split(';');
    var matches = new Array();
    for(var i=0;i<cookie_pairs.length;i++) {
        var cookie_item = cookie_pairs[i].split('=');
        if(isDefined(cookie_item) && isDefined(cookie_item[0]) && isDefined(cookie_item[1])) {
            var cname = cookie_item[0].replace(/^\s+|\s+$/g, '');
            var cvalue = cookie_item[1].replace(/^\s+|\s+$/g, '');
            if(cname.indexOf(prefix) == 0) {
                var tmp = new Array();
                tmp['name'] = cname;
                tmp['value'] = cvalue;
                matches.push(tmp);
            }
        }        
    }
    if(matches.length > 0) {
        for(var j=0;j<matches.length;j++) {
            if(matches[j]['value'] == 'open') {
                try {
                        $('#'+matches[j]['name']).trigger('click');
                    } catch (e) {

                    } finally {
                        
                    }
            }
        }
    }
}

function isDefined( variable)
{
    return (typeof variable == "undefined") ? false : true;
}

function getCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function initSponsorcreation() {
    alert('bllubb');
}
