$(document).ready(function () {
	
	$('a[rel*=facebox]').facebox({
		loadingImage : 'system/js/facebox/loading.gif',
		closeImage   : 'system/js/facebox/closelabel.png'
	});
	
	$('#template_suche').livequery('click', function() {
		
		$('#template_suchbox').show();
		
		var suchwort = '';
		
		$.ajax({
			url: 'ajax/ajax.autocomplete.php',
			type: 'post',
			data: 'suchwort='+suchwort,
			beforeSend: function() {
				
			},
			success: function(data) {
				$('#template_suchbox').empty();
				$('#template_suchbox').html(data);
			}
		});
		
	});
	
	$('#template_suche').livequery('keypress', function() {
		
		var suchwort = $('#template_suche').val();
		
		$.ajax({
			url: 'ajax/ajax.autocomplete.php',
			type: 'post',
			data: 'suchwort='+suchwort,
			beforeSend: function() {
				
			},
			success: function(data) {
				$('#template_suchbox').empty();
				$('#template_suchbox').html(data);
			}
		});
		
	});
	
	$('#template_suchbox_close').livequery('click', function() {
		$('#template_suchbox').empty();
		$('#template_suchbox').hide();
	});
	
	$('.tipsyn').tipsy({gravity: 'n', opacity: 1.0});
	$('.tipsys').tipsy({gravity: 's', opacity: 1.0});
	$('.tipsye').tipsy({gravity: 'e', opacity: 1.0});
	$('.tipsyw').tipsy({gravity: 'w', opacity: 1.0});
	
	$('a[rel=tipsyn]').tipsy({gravity: 'n', opacity: 1.0});
	$('a[rel=tipsys]').tipsy({gravity: 's', opacity: 1.0});
	$('a[rel=tipsye]').tipsy({gravity: 'e', opacity: 1.0});
	$('a[rel=tipsyw]').tipsy({gravity: 'w', opacity: 1.0});
	
	 $('.has-navmenu').click(function(){
        $('.navmenu').fadeOut();
        $('.has-navmenu').removeClass('navopen');
        $(this).addClass('navopen');
        $(this).next().fadeIn();
        return false;
    });

    $('.navmenu .close').click(function(){
        $(this).parents('.navmenu').fadeOut();
        $('.has-navmenu').removeClass('navopen');
    });
	
	ajax_update();
	var updateTimer = window.setInterval(ajax_update, 45000);
	
	$('.nav-icon').click(function() {
		$('li').removeClass('active');
		$(this).parent().addClass('active');
	});
		
	$('.profil_pinnwand_fotoupload').livequery('click', function(e) { 
		
		$('.profil_pinnwand_fotobox').slideToggle();
		$('.pinnwand_submit_wrapper').show();
		
	});
	

	$('.pinnwandinput').livequery('click', function(e) { 
		$('.pinnwand_submit_wrapper').show();
	});
	
	response = new Array();
	response['bilder'] = new Array();
	
	var responseTemp = null; 
	
	$('#fotoinput').live('change', function() { 

		$("#pinnwand_form").ajaxForm({
			target: null,
			replaceTarget: false,
			beforeSubmit: function() { 
										$('#pinnwand_option').val('pinnwand_fotoupload');
										$('#fotoloader').show();
									 },
			success: function(responseText) { 
									$('#pinnwand_option').val('pinnwand_seteintrag');
									$('#fotoloader').hide(); 
									$('#fotoinput').val('');
									
									responseTemp = responseText.split('||');
									
									response['bilder'].push(responseTemp[0]);
									$('#fotoimages').prepend('<img src="'+responseTemp[1]+'"><br>');
								}
		}).submit();
		
		
	});
	
	
	$('.pinnwand_submit').livequery('click', function(e) { 

		if ($('.pinnwandinput').val() != '') {
		
			$("#pinnwand_form").ajaxForm({
				target: '#pinnwand_preview',
				data: response,
				beforeSubmit: function() { 
					
										 },
				success: function() { 
										$('.pinnwandinput').val('');
										$('ul#fotoimages').empty();
										$('.pinnwand_submit_wrapper').hide();
										$('.profil_pinnwand_fotobox').hide();
									}
			}).submit();
			
		} else {
			$('.pinnwandinput').css('background-color', '#FF0000');
		}
				
	});
	
	$('.pinnwand_eintrag') 
    .livequery(function(){ 
    // use the helper function hover to bind a mouseover and mouseout event 
        $(this) 
            .hover(function() { 
            	var eintragId = $(this).attr('id').replace('peintrag_','');
    			$('#delete_'+eintragId).show();
            }, function() { 
            	var eintragId = $(this).attr('id').replace('peintrag_','');
    			$('#delete_'+eintragId).hide();
            }); 
    }, function() { 
        // unbind the mouseover and mouseout events 
        $(this) 
            .unbind('mouseover') 
            .unbind('mouseout'); 
    }); 
	
	
	$('.show_comments').livequery('click', function(e) { 
		
		var parents = $(this).attr('id');
		parents = parents.split('_');
		$('#comments_'+parents[0]+'_'+parents[1]).children().slideDown();
		$(this).fadeOut();
		
	});
	
	$('.showcommentform').livequery('click', function(e) { 
		
		var parents = $(this).attr('id');
		parents = parents.split('_');
		var parentId = parents[0];
		var parentMod = parents[1];
		
		$('#comment_schreiben_'+parentMod+'_'+parentId).slideToggle();
		
	});
	
	$('.comment_input').livequery('keypress', function(e) { 

		var parents = $(this).parent().attr('id').replace('comment_schreiben_','');
		parents = parents.split('_');
		var parentId = parents[0];
		var parentMod = parents[1];
		var text = $(this).val();
		
		if (e.which == 13) {

			e.preventDefault();

			if (text != '' && text != 'Bitte Text eingeben.' && text != 'Zum speichern Enter drücken...') {
			
				$.ajax({
					type: 'post',
					url: 'system/inc/comment.inc.php',
					data: 'option=setEintrag&parentId='+parentId+'&parentMod='+parentMod+'&text='+text,
					beforeSend: function(){
						$(this).val('Bitte warten...');
					},
					success: function(data){
						$('#comments_'+parentId+'_'+parentMod).prepend(data);
						$('#comment_schreiben_'+parentId+'_'+parentMod+' > *').val('Zum speichern Enter drücken...');
					}
				});
				
			} else {
				
				$(this).val('Bitte Text eingeben.');
				
			}
						
		}
				
	});
	
	$('.plusanzahl').livequery('click', function(e) { 
		
		var anzahl = $(this).text();
			anzahl = anzahl.replace('(','');
			anzahl = anzahl.replace(')','');
			anzahl = parseInt(anzahl);
			
			if (anzahl > 0) {
			
				var parents = $(this).attr('id').replace('plusanzahl_','');
				parents = parents.split('_');
				jQuery.facebox({ ajax: 'system/inc/plus.inc.php?option=showuser&parentId='+parents[0]+'&parentMod='+parents[1] })
				
			}
		
	});
	
	$('.pluslink').livequery('click', function(e) { 
		
		var parents = $(this).attr('id').replace('pluslink_','');
		parents = parents.split('_');
		
		$.ajax({
			type: 'post',
			url: 'system/inc/plus.inc.php',
			data: 'option=setEintrag&parentId='+parents[0]+'&parentMod='+parents[1]+'&label='+parents[2],
			beforeSend: function(){
				
				
			},
			success: function(data){
				var inhalt = data.split('||');
				$('#pluslink_'+parents[0]+'_'+parents[1]+'_'+parents[2]).html(inhalt[0]);
				$('#plusanzahl_'+parents[0]+'_'+parents[1]).text(inhalt[1]);
			}
		});	
		
	});
	

});

function ajax_update() {
	
//	$.ajax({
//		type: 'post',
//		url: 'ajax/ajax.user.php',
//		data: 'option=usernav',
//		beforeSend: function(){
//		},
//		success: function(data){
//			$('#ajax_usernav').empty();
//			$('#ajax_usernav').prepend(data);
//		}
//	});
	
	$.ajax({
		url: 'ajax/ajax.listen.php',
		type: 'get',
		dataType: 'json',
		data: 'loadlisten=true',
		beforeSend: function(){
			
		},
		success: function(data){
			
			/*
			
			var userstatus = String(data.userstatus);
			if (userstatus == 1) {
				window.location.reload();
			}
			
			$.each(data.listen, function(listenname, listendata) {
				
				$('.liste_'+String(listenname)).empty();
				
				$.each(data.listen[listenname], function(listkey, listvalue) {

					$('.liste_'+String(listenname)).prepend(String(listvalue));
					
				});
				
			});
			
			*/
			
//			if (data.banners) {
//			
//				$.each(data.banners, function(bannerKey, bannerValue) {
//					
//					$('#'+bannerValue.position).empty();
//					$('#'+bannerValue.position).append('<img src="media/banner/'+bannerValue.datei+'">');
//					
//				});
//				
//			}
			
			var anzahlnachrichten = String(data.anzahlnachrichten);
			
			if (anzahlnachrichten > 0) {
				
				$('.nav_nachrichten').addClass('aktiv');
				
				$('.nav_nachrichten_anzahl').addClass('aktiv');
				$('.nav_nachrichten_anzahl').empty();
				$('.nav_nachrichten_anzahl').append(anzahlnachrichten);
				
				$('#ajax_nachrichten').empty();
				
				$.each(data.nachrichten, function(key, value) {
					
					$('#ajax_nachrichten').prepend('<table onclick="window.location.href=\''+value.nachricht_link+'\'; $(this).parent().parent().fadeOut(200);" class="link"><tr><td width="70"><img src="'+value.user_image+'" class="imagebg_2"></td><td>'+value.nachricht_betreff+'<br>'+value.user_name+'</td></tr></table>');
					
				});
				
			} else {
				
				$('#ajax_nachrichten').empty();
				$('#ajax_nachrichten').prepend('<h4>Keine neuen Nachrichten</h4>');
				
			}
			
			var anzahlanfragen = String(data.anzahlanfragen);
			
			if (anzahlanfragen > 0) {
				
				$('.nav_anfragen').addClass('aktiv');
				
				$('.nav_anfragen_anzahl').addClass('aktiv');
				$('.nav_anfragen_anzahl').empty();
				$('.nav_anfragen_anzahl').append(anzahlanfragen);
				
				$('#ajax_anfragen').empty();
				
				$.each(data.anfragen, function(key, value) {
					
					$('#ajax_anfragen').prepend('<table width="100%"><tr><td width="70"><a href="'+value.user_link+'"><img src="'+value.user_image+'" class="imagebg_2"></a></td><td><span onclick="window.location.href=\''+value.user_link+'\'" class="link">'+value.link_text+':<br>'+value.user_name+'</span><br>'+value.user_text+'</td><td width="40"><a class="button green" href="'+value.link_annehmen+'"><span class="icon icon3"></span></a> <a class="button red" href="'+value.link_ablehnen+'"><span class="icon icon186"></span></a></td></tr></table>');
					
				});
				
			} else {
				
				$('#ajax_anfragen').empty();
				$('#ajax_anfragen').prepend('<h4>Keine Anfragen</h4>');
				
			}
			
			var userloggendIn = String(data.userloggendIn);
			
			if (userloggendIn > 0) {
				$('ajax_username').empty();
				$('ajax_username').prepend(userloggenInName+'<span class="arrow-down"></span>');
			}
			
			var anzahlnotifications = String(data.anzahlnotifications);
			
			if (anzahlnotifications > 0) {
				
				$('.nav_notifications').addClass('aktiv');
				
				$('.nav_notifications_anzahl').addClass('aktiv');
				$('.nav_notifications_anzahl').empty();
				$('.nav_notifications_anzahl').append(anzahlnotifications);
				
				$('.nav_notifications').attr('href', '/9/profil/benachrichtigungen/');
				
			} else { 
				
				$('.nav_notifications').removeClass('aktiv');
				
			}
			
		}
	});
	
}

(function($) {
	 
	 function fixTitle($ele) {
	     if ($ele.attr('title') || typeof($ele.attr('original-title')) != 'string') {
	         $ele.attr('original-title', $ele.attr('title') || '').removeAttr('title');
	     }
	 }
	 
	 function Tipsy(element, options) {
	     this.$element = $(element);
	     this.options = options;
	     this.enabled = true;
	     fixTitle(this.$element);
	 }
	 
	 Tipsy.prototype = {
	     show: function() {
	         var title = this.getTitle();
	         if (title && this.enabled) {
	             var $tip = this.tip();
	             
	             $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'html'](title);
	             $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
	             $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
	             
	             var pos = $.extend({}, this.$element.offset(), {
	                 width: this.$element[0].offsetWidth,
	                 height: this.$element[0].offsetHeight
	             });
	             
	             var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight;
	             var gravity = (typeof this.options.gravity == 'function')
	                             ? this.options.gravity.call(this.$element[0])
	                             : this.options.gravity;
	             
	             var tp;
	             switch (gravity.charAt(0)) {
	                 case 'n':
	                     tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
	                     break;
	                 case 's':
	                     tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
	                     break;
	                 case 'e':
	                     tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
	                     break;
	                 case 'w':
	                     tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
	                     break;
	             }
	             
	             if (gravity.length == 2) {
	                 if (gravity.charAt(1) == 'w') {
	                     tp.left = pos.left + pos.width / 2 - 15;
	                 } else {
	                     tp.left = pos.left + pos.width / 2 - actualWidth + 15;
	                 }
	             }
	             
	             $tip.css(tp).addClass('tipsy-' + gravity);
	             
	             if (this.options.fade) {
	                 $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
	             } else {
	                 $tip.css({visibility: 'visible', opacity: this.options.opacity});
	             }
	         }
	     },
	     
	     hide: function() {
	         if (this.options.fade) {
	             this.tip().stop().fadeOut(function() { $(this).remove(); });
	         } else {
	             this.tip().remove();
	         }
	     },
	     
	     getTitle: function() {
	         var title, $e = this.$element, o = this.options;
	         fixTitle($e);
	         var title, o = this.options;
	         if (typeof o.title == 'string') {
	             title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
	         } else if (typeof o.title == 'function') {
	             title = o.title.call($e[0]);
	         }
	         title = ('' + title).replace(/(^\s*|\s*$)/, "");
	         return title || o.fallback;
	     },
	     
	     tip: function() {
	         if (!this.$tip) {
	             this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"/></div>');
	         }
	         return this.$tip;
	     },
	     
	     validate: function() {
	         if (!this.$element[0].parentNode) {
	             this.hide();
	             this.$element = null;
	             this.options = null;
	         }
	     },
	     
	     enable: function() { this.enabled = true; },
	     disable: function() { this.enabled = false; },
	     toggleEnabled: function() { this.enabled = !this.enabled; }
	 };
	 
	 $.fn.tipsy = function(options) {
	     
	     if (options === true) {
	         return this.data('tipsy');
	     } else if (typeof options == 'string') {
	         return this.data('tipsy')[options]();
	     }
	     
	     options = $.extend({}, $.fn.tipsy.defaults, options);
	     
	     function get(ele) {
	         var tipsy = $.data(ele, 'tipsy');
	         if (!tipsy) {
	             tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
	             $.data(ele, 'tipsy', tipsy);
	         }
	         return tipsy;
	     }
	     
	     function enter() {
	         var tipsy = get(this);
	         tipsy.hoverState = 'in';
	         if (options.delayIn == 0) {
	             tipsy.show();
	         } else {
	             setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
	         }
	     };
	     
	     function leave() {
	         var tipsy = get(this);
	         tipsy.hoverState = 'out';
	         if (options.delayOut == 0) {
	             tipsy.hide();
	         } else {
	             setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
	         }
	     };
	     
	     if (!options.live) this.each(function() { get(this); });
	     
	     if (options.trigger != 'manual') {
	         var binder   = options.live ? 'live' : 'bind',
	             eventIn  = options.trigger == 'hover' ? 'mouseenter' : 'focus',
	             eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
	         this[binder](eventIn, enter)[binder](eventOut, leave);
	     }
	     
	     return this;
	     
	 };
	 
	 $.fn.tipsy.defaults = {
	     delayIn: 0,
	     delayOut: 0,
	     fade: false,
	     fallback: '',
	     gravity: 'n',
	     html: false,
	     live: false,
	     offset: 0,
	     opacity: 0.8,
	     title: 'title',
	     trigger: 'hover'
	 };

	 $.fn.tipsy.elementOptions = function(ele, options) {
	     return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
	 };
	 
	 $.fn.tipsy.autoNS = function() {
	     return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
	 };
	 
	 $.fn.tipsy.autoWE = function() {
	     return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
	 };
	 
	})(jQuery);

(function($) {
    $.fn.oembed = function(url, options, callback) {

        options = $.extend(true, $.fn.oembed.defaults, options);

        return this.each(function() {

            var container = $(this),
				resourceURL = (url != null) ? url : container.attr("href"),
				provider;

            if (!callback) callback = function(container, oembed) {			
				 $.fn.oembed.insertCode(container, options.embedMethod, oembed);
            };

            if (resourceURL != null) {
                provider = getOEmbedProvider(resourceURL);

                if (provider != null) {
                    provider.maxWidth = options.maxWidth;
                    provider.maxHeight = options.maxHeight;					
					provider.params = options[provider.name] || {};
                    provider.embedCode(container, resourceURL, callback);
                    return;
                }
            }

            callback(container, null);
        });
    };

    // Plugin defaults
    $.fn.oembed.defaults = {
        maxWidth: null,
        maxHeight: null,
		embedMethod: "replace" // "auto", "append", "fill"
    };
	
	$.fn.oembed.insertCode = function(container, embedMethod, oembed) {
		switch(embedMethod)
		{
			case "auto":				
                if (container.attr("href") != null) {
					insertCode(container, "append", oembed);
				}
				else {
					insertCode(container, "replace", oembed);
				};
				break;
			case "replace":	
				container.replaceWith(oembed.code);
				break;
			case "fill":
				container.html(oembed.code);
				break;
			case "append":
                var oembedContainer = container.next();
				if (oembedContainer == null || !oembedContainer.hasClass("oembed-container")) {
					oembedContainer = container
						.after('<div class="oembed-container"></div>')
						.next(".oembed-container");
					if (oembed != null && oembed.provider_name != null)
					    oembedContainer.toggleClass("oembed-container-" + oembed.provider_name);		
				}
				oembedContainer.html(oembed.code);				
				break;			
		}
	}	

    $.fn.oembed.getPhotoCode = function(url, data) {
	    var alt = data.title ? data.title : '';
        alt += data.author_name ? ' - ' + data.author_name : '';
        alt += data.provider_name ? ' - ' +data.provider_name : '';
        var code = '<div><a href="' + url + '" target="_blank"><img src="' + data.url + '" alt="' + alt + '"/></a></div>';
        if (data.html)
            code += "<div>" + data.html + "</div>";
        return code;
    };

    $.fn.oembed.getVideoCode = function(url, data) {
        var code = data.html;
        return code;
    };

    $.fn.oembed.getRichCode = function(url, data) {
        var code = data.html;
        return code;
    };

    $.fn.oembed.getGenericCode = function(url, data) {
        var title = (data.title != null) ? data.title : url,
			code = '<a href="' + url + '">' + title + '</a>';
        if (data.html)
            code += "<div>" + data.html + "</div>";
        return code;
    };

    $.fn.oembed.isAvailable = function(url) {
        var provider = getOEmbedProvider(url);
        return (provider != null);
    };

    /* Private Methods */
    function getOEmbedProvider(url) {
        for (var i = 0; i < providers.length; i++) {
            if (providers[i].matches(url))
                return providers[i];
        }
        return null;
    }

    var providers = [
        new OEmbedProvider("fivemin", "5min.com"),
        new OEmbedProvider("amazon", "amazon.com"),
        new OEmbedProvider("flickr", "flickr", "http://flickr.com/services/oembed", "jsoncallback"),    
        new OEmbedProvider("googlevideo", "video.google."),
        new OEmbedProvider("hulu", "hulu.com"),
        new OEmbedProvider("imdb", "imdb.com"),
        new OEmbedProvider("metacafe", "metacafe.com"),
        new OEmbedProvider("qik", "qik.com"),
        new OEmbedProvider("revision3", "slideshare"),
        new OEmbedProvider("slideshare", "5min.com"),

        new OEmbedProvider("twitpic", "twitpic.com"),
        new OEmbedProvider("viddler", "viddler.com"),
        new OEmbedProvider("vimeo", "vimeo.com", "http://vimeo.com/api/oembed.json"),
        new OEmbedProvider("wikipedia", "wikipedia.org"),
        new OEmbedProvider("wordpress", "wordpress.com"),
        new OEmbedProvider("youtube", "youtube.com")
    ];

    function OEmbedProvider(name, urlPattern, oEmbedUrl, callbackparameter) {
        this.name = name;
        this.urlPattern = urlPattern;
        this.oEmbedUrl = (oEmbedUrl != null) ? oEmbedUrl : "http://oohembed.com/oohembed/";
        this.callbackparameter = (callbackparameter != null) ? callbackparameter : "callback";
        this.maxWidth = 200;
        this.maxHeight = 100;

        this.matches = function(externalUrl) {
            // TODO: Convert to Regex
            return externalUrl.indexOf(this.urlPattern) >= 0;
        };

        this.getRequestUrl = function(externalUrl) {

            var url = this.oEmbedUrl;

            if (url.indexOf("?") <= 0)
                url = url + "?";

			var qs = "";

			for (var i in this.params) {
                // We don't want them to jack everything up by changing the callback parameter
                if (i == this.callbackparameter)
                  continue;
                
				// allows the options to be set to null, don't send null values to the server as parameters
                if (this.params[i] != null)
                	qs += "&" + escape(i) + "=" + this.params[i];
            }			

            url += "format=json";
			
			if (this.maxWidth != null)
				url += "&maxwidth=" + this.maxWidth;
				
			if (this.maxHeight != null)
				url += "&maxheight=" + this.maxHeight;			
				
			url += "&url=" + escape(externalUrl) + 			
					qs + 
					"&" + this.callbackparameter + "=?";
					
            return url;
        }

        this.embedCode = function(container, externalUrl, callback) {

            var request = this.getRequestUrl(externalUrl);

            $.getJSON(request, function(data) {

                var oembed = $.extend(data);

                var code, type = data.type;

                switch (type) {
                    case "photo":
                        oembed.code = $.fn.oembed.getPhotoCode(externalUrl, data);
                        break;
                    case "video":
                        oembed.code = $.fn.oembed.getVideoCode(externalUrl, data);
                        break;
                    case "rich":
                        oembed.code = $.fn.oembed.getRichCode(externalUrl, data);
                        break;
                    default:
                        oembed.code = $.fn.oembed.getGenericCode(externalUrl, data);
                        break;
                }

                callback(container, oembed);
            });
        }
    }
})(jQuery);

(function($) {

	function hideFieldsetContent(obj, options){

		if(options.animation==true)

			obj.find('div').slideUp(options.speed);

		else

			obj.find('div').hide();

		

		obj.removeClass("expanded");

		obj.addClass("collapsed");

	}

	

	function showFieldsetContent(obj, options){

		if(options.animation==true)

			obj.find('div').slideDown(options.speed);

		else

			obj.find('div').show();

		

		obj.removeClass("collapsed");

		obj.addClass("expanded");

	}

	

	$.fn.coolfieldset = function(options){

		var setting={collapsed:false, animation:true, speed:'medium'};

		$.extend(setting, options);

		

		this.each(function(){

			var fieldset=$(this);

			var legend=fieldset.children('legend');

			

			if(setting.collapsed==true){

				legend.toggle(

					function(){

						showFieldsetContent(fieldset, setting);

					},

					function(){

						hideFieldsetContent(fieldset, setting);

					}

				)

				

				hideFieldsetContent(fieldset, {animation:false});

			}

			else{

				legend.toggle(

					function(){

						hideFieldsetContent(fieldset, setting);

					},

					function(){

						showFieldsetContent(fieldset, setting);

					}

				)

			}

		});

	}

})(jQuery);

(function($) {
	function autosuggest(callBackUrl, textField){
		this.divId="suggestions_holder";
		this.hovered=false;
		this.arrData=null;
		
		this.textField=textField;
		this.callBackUrl=callBackUrl;
		
		var width=this.textField.width() + 3;
		var minChars=1;
		var currRow=0;
		var suggestRow="suggest_row";
		var suggestItem="suggest_item";
		
		this.idField=null;
		this.submitOnSelect=false;
		this.thumbnail=false;
		this.description=false;
		
		this.textField.after('<div class="suggestions" id="' + this.divId + '"></div>');
		this.textField.attr("autocomplete", "off");
		
		this.holder=this.textField.next("#" + this.divId);
		this.holder.hide();
		
		this.onSelected=null;
		
		var me=this;
		this.textField.keyup(
			function(e){
				if(e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40 && e.keyCode!=13){
					if($(this).val().length>=minChars){
						$.ajax({
							url:me.callBackUrl + $(this).val(),
							success:function(data){
								try{
									me.arrData=$.parseJSON(data);
									
									var arr=me.arrData;
									var html="";
									
									currRow=0;
									
									if(arr==null){
										me.hide();
									}
									else{
										if(arr.length>0){
											for(i=0;i<arr.length;i++){
												cssClass=suggestItem;
												
												if(i==0){
													cssClass+=" first";
												}
												if(i==(arr.length-1)){
													cssClass+=" last";
												}
												
												var id_field='';
												if(me.idField!=null){
													id_field=' id_field="' + arr[i].id + '"';
												}
												
												var thumb="";
												if(me.thumbnail==true){
													var style="";
													if(arr[i].thumbnail!=undefined){
														style=' style="background-image:url(' + arr[i].thumbnail + ');"';
													}
													thumb='<div class="thumbnail"' + style + '></div>';
												}
												
												var desc="";
												if(me.description==true){
													if(arr[i].description!=undefined){
														desc='<div class="description">' + arr[i].description + '</div>';
													}
												}
												
												html+='<div id="' + suggestRow + (i+1) + '" class="' + cssClass + '"' + id_field + ' seq_id="' + i + '" >' + thumb + '<div class="suggestion_title">' + arr[i].data.replace(new RegExp('(' + me.textField.val() + ')', 'gi'), "$1") + '</div>' + desc + '</div>';
											}
											
											me.holder.html(html);
											
											for(i=1;i<=arr.length;i++){
												var target=me.holder.find("#" + suggestRow + i);
												target.mouseover(function(e){
													me.hovered=true;
													me.unSelectAll(this);
													$(this).addClass("selected");
												});
												
												target.mouseout(function(e){
													me.hovered=false;
													$(this).removeClass("selected");
												});
												
												target.click(function(e){
													me.textField.val($(this).find(".suggestion_title").text());
													if(me.idField!=null){
														me.idField.val($(this).attr("id_field"));
													}
													
													// Callback function
													if(me.onSelected!=null){
														me.onSelected.call(this, me.arrData[$(this).attr("seq_id")]);
													}
													
													if(me.submitOnSelect==true){
														$("form").has(me.textField).submit();
													}
													
													me.hide();
												});
											}
											
											me.show(me.holder.find("." + suggestItem).height() * arr.length);
										}
										else{
											me.hide();
										}
									}
								}
								catch(e){
									alert('Sorry, an error has occured!');
								}
							},
							error: function(xhr, status, ex){
								alert('Sorry, an error has occured!');
							}
						});
					}
					else{
						me.hide();
					}
				}
				else{
					if(me.holder.css("display")!="none"){
						checkKey(e);
					}
					else{
						// Callback function
						if(me.onSelected!=null){
							me.onSelected.call(this, null);
						}
					}
				}
			}
		);
		
		this.textField.bind(
			"blur",
			function(e){
				if(me.idField!=null){
					if(me.checkSelected(me.textField.val())==false){
						me.textField.val("");
						me.idField.val("");
					}
				}
				
				if(me.hovered==false){
					me.hide();
				}
				else{
					me.hovered=false;
				}
			}
		);
		
		this.show=function(height){
			this.holder.css({
				"position":"absolute",
				"left":this.textField.position().left + "px",
				"top":this.textField.position().top + this.textField.height() + 5 + "px",
				"height":height + "px"
			});
			
			this.holder.css({
				"width":width + "px"
			});
			
			this.holder.find("." + suggestItem).css({
				"width":width + "px",
				"overflow":"hidden"
			});
			
			this.holder.show();
		}
		
		this.hide=function(){
			this.holder.hide();
		}
		
		this.unSelectAll=function(div){
			var id=$(div).attr("id");
			var rows=this.holder.find("." + suggestItem).get().length;
			
			for(i=1;i<=rows;i++){
				this.holder.find("#" + suggestRow + i).removeClass("selected");
			}
			
			currRow=parseInt(id.replace(suggestRow, ""));
			var rgx=/^[0-9]+$/;
			if(!rgx.test(currRow)){
				currRow=0;
			}
		}
		
		this.setWidth=function(w){
			width=w;
		}
		
		this.setMinChars=function(c){
			minChars=c;
		}
		
		this.preventEnter=function(){
			this.textField.keypress(
				function(e){
					if(e.keyCode==13){
						return false;
					}
					
					return true;
				}
			);
		}
		
		this.checkSelected=function(data){
			if(this.arrData!=null){
				for(var i=0;i<this.arrData.length;i++){
					if(this.arrData[i].data==data){
						return true;
					}
				}
			}
			
			return false;
		}
		
		function checkKey(e){
			if(me.holder.css("display")!="none"){
				var rows=me.holder.find("." + suggestItem).get().length;
				if(e.keyCode==40){
					currRow++;
					if(currRow<=rows){
						if(currRow>0){
							me.holder.find("#" + suggestRow + (currRow-1)).removeClass("selected");
						}
						
						var target=me.holder.find("#" + suggestRow + currRow);
						
						target.addClass("selected");
						me.textField.val(target.find(".suggestion_title").text());
						if(me.idField!=null){
							me.idField.val(target.attr("id_field"));
						}
					}
					else{
						currRow=rows;
					}
				}
				else if(e.keyCode==38){
					currRow--;
					if(currRow>0){
						if(currRow<rows){
							me.holder.find("#" + suggestRow + (currRow+1)).removeClass("selected");
						}
						
						var target=me.holder.find("#" + suggestRow + currRow);
						
						target.addClass("selected");
						me.textField.val(target.find(".suggestion_title").text());
						if(me.idField!=null){
							me.idField.val(target.attr("id_field"));
						}
					}
					else{
						currRow=1;
					}
				}
				else if(e.keyCode==13){
					if(me.idField!=null){
						if(me.checkSelected(me.textField.val())==false){
							me.textField.val("");
							me.idField.val("");
						}
					}
					
					// Callback function
					if(me.onSelected!=null){
						if(currRow>0){
							me.onSelected.call(this, me.arrData[currRow-1]);
						}
						else{
							me.onSelected.call(this, null);
						}
					}
					
					me.hide();
				}
			}
			else{
				// Callback function
				if(me.onSelected!=null){
					me.onSelected.call(this, null);
				}
			}
			
			return true;
		}
	}

	$.fn.coolautosuggest = function(options) {
		var settings = {
			width: null,
			minChars: null,
			idField: null,
			submitOnSelect: false,
			showThumbnail : false,
			showDescription : false,
			onSelected : null
		};
		$.extend(settings, options);
		
		return this.each(function() {
			var obj = new autosuggest(settings.url, $(this));
			
			if(settings.width!=null){
				obj.setWidth(settings.width);
			}
			
			if(settings.minChars!=null){
				obj.setMinChars(settings.minChars);
			}
			
			if(settings.idField!=null){
				obj.idField=settings.idField;
				obj.preventEnter();
			}
			
			if(settings.submitOnSelect==true){
				obj.submitOnSelect=true;
			}
			else{
				obj.preventEnter();
			}
			
			if(settings.showThumbnail==true){
				obj.thumbnail=settings.showThumbnail;
			}
			
			if(settings.showDescription==true){
				obj.description=settings.showDescription;
			}
			
			if(obj.idField!=null){
				if(obj.checkSelected(obj.textField.val())==false){
					obj.textField.val("");
					obj.idField.val("");
				}
			}
			
			if($.isFunction(settings.onSelected)==true){
				obj.onSelected=settings.onSelected;
			}
		});
	}
})(jQuery);
$(document).ready(function() {
	
	$(".image_stack").delegate('img', 'mouseenter', function() {
		if ($(this).hasClass('stackphotos')) {
			var $parent = $(this).parent();
			$parent.find('img#photo1').addClass('rotate1');
			$parent.find('img#photo2').addClass('rotate2');
			$parent.find('img#photo3').addClass('rotate3');
			$parent.find('img#photo1').css("left","150px"); 
			$parent.find('img#photo3').css("left","50px");
		}
	})
	.delegate('img', 'mouseleave', function() {
		$('img#photo1').removeClass('rotate1');
			$('img#photo2').removeClass('rotate2');
			$('img#photo3').removeClass('rotate3');
			$('img#photo1').css("left","");
			$('img#photo3').css("left","");
	});;
	
	$(".dropdown .button, .dropdown button").click(function () {
		if (!$(this).find('span.toggle').hasClass('active')) {
			$('.dropdown-slider').slideUp();
			$('span.toggle').removeClass('active');
		}

		$(this).parent().find('.dropdown-slider').slideToggle('fast');
		$(this).find('span.toggle').toggleClass('active');
		
		return false;
	});
	
	$('ddm').click(function(){
		$('.dropdown-slider').slideUp();
	});

});

$(document).bind('click', function (e) {
	if (e.target.id != $('.dropdown').attr('class')) {
		$('.dropdown-slider').slideUp();
		$('span.toggle').removeClass('active');
	}
});
