top_scroller = {
    collection: new Array(),
    current: 0,
    start: function() {
        if (top_scroller.collection.length == 0) top_scroller.collection = $('.top_content');

        $('#top_body').width(424*top_scroller.collection.length);
    },

    next: function() {
        if (top_scroller.collection.length == 0) return false;
        var first = $('#top_body');

        top_scroller.current++;
        if (top_scroller.current == top_scroller.collection.length) {
            first.animate({'marginLeft': '0px'});
            top_scroller.current = 0;
        } else {
            var cm = first.css('margin-left').replace('px', '');
            if (cm == 'auto') cm = 0;
            cm = parseFloat(cm);

            first.animate({'marginLeft': (cm-420)+'px'});
        }
        return false;
    }
}

$(document).ready(function() {
   $('#content_hidden').hide();
   $('#flick_twit_cont a').mouseover(function(){
        var class_name = $(this).attr("rel");
        class_name = '#' + class_name;
        var data_info = $(class_name).html();
		$('#tooltip2').find('.tt_w2').html(data_info);
    }).tooltip({
        events: {
            def: "mouseover,blur",
            tooltip: "mouseover,mouseout"
        },
        // place tooltip on the right edge
        position: "top center",
        // use the built-in fadeIn/fadeOut effect
        effect: 'fade',
        //effect: 'slide',
        offset: [0, -87],
        // use this single tooltip element
        tip: '#tooltip2'
    });
	$('#link_form').tooltip({
        events: {
            def: "click,def",
            tooltip: "click,def"
        },
        // place tooltip on the right edge
        position: "bottom center",
        // use the built-in fadeIn/fadeOut effect
        effect: 'fade',
        //effect: 'slide',
        offset: [0, -150],
        // use this single tooltip element
        tip: '#tooltip4'
    }).click(function(){
        $('.error, .success').hide().removeClass('centered');
        $(".focus_el").css({
			'border' : '1px solid #B8B8B8',
			'background' : "#ffffff"
		});
        $('#order_form').clearForm().show();
		return false;
	});
	var el_focus = $(".focus_el");
	$(el_focus).focus(function () {
		$(el_focus).css({
			'border' : '1px solid #B8B8B8',
			'background' : "#ffffff"
		});
		$(this).css({
			'border' : '1px solid #B8B8B8',
			'background' : "#dcffb6"
		});
	});
    $('#header_text').find('a[href^=#hidden]').click(function() {
        var id = $(this).attr("rel");
        var info = $(id).html();
        $('#tooltip3').find('.tt_w2').html(info);
        activate_links();
    }).tooltip({
        events: {
            def: "click,def",
            tooltip: "click,def"
        },
        // place tooltip on the right edge
        position: "bottom center",
        // use the built-in fadeIn/fadeOut effect
        effect: 'fade',
        //effect: 'slide',
        offset: [0, -150],
        // use this single tooltip element
        tip: '#tooltip3'
    });
	$('img.close_tt').click(function(){
		$(this).parent().fadeOut(400);
	});
    $('a[href=#top_next]').click(function() {
        top_scroller.next();
        return false;
    });
   
   $('#loading').ajaxStart(function() {$(this).show();});
   $('#loading').ajaxStop(function() {$(this).fadeOut();});

   top_scroller.start();
    
    $('#order_form').submit(function() {
        var options = {
            dataType: 'json',
            success: function(data) {
                $('.error').hide();
                if (data.success) {
                    $('#order_form').hide();
                    $('#success').addClass('centered').show();
                    setTimeout(function(){$('#tooltip4').fadeOut()}, 2000);
                } else {
                    $('#order_form').hide();
                    $.each(data.errors, function(i, n) {
                        $('#'+i+'_error').show().addClass('centered');
                    });
                    setTimeout(function() {
                        $('.error').removeClass('centered').hide();
                        $('#order_form').show();
                    }, 2000);
                }
            }
        }

        $(this).ajaxSubmit(options);
        return false;
    });
});


ghtml = {
    options: function(list, selected, first) {
        var code = '';
        if (first && first !== undefined) {
            code += '<option value="">'+first+'</option>';
        }
        $.each(list, function(i, n) {
            code += '<option value="'+i+'" ';
            if (selected && selected !== undefined && selected == i) {
                code += 'selected = "selected"';
            }
            code += '>'+n+'</option>';
        });
        return code;
    }
}

activate_links = function() {
    $(document).ready(function() {
        $('a[href^=#hidden_]').click(function() {
            var id = $(this).attr("rel");
            var info = $(id).html();
            $('#tooltip3').find('.tt_w2').html(info);
            activate_links();
        });
    });
}
