function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function confirmStarRating(data) {
	if(data != 'rated') { 
		$(".starRating").data("stars").select(0);
		alert(data);
	}
}


$(document).ready(function() {

	$(".categories").each(function(){
        $(this).css("height", $(this).height()+"px");
        $(this).hide();
    });  

	$(".trigger").click(function(){
		$(this).parent().nextAll(".categories").eq(0).slideToggle("slow,");
		$(this).toggleClass("active");
	});


	$('#navMain ul').superfish({ 
	    delay: 500,                                     // one second delay on mouseout
	    animation: {opacity:'show',height:'show'},      // fade-in and slide-down animation
	    speed: 'fast',                                  // faster animation speed
	    autoArrows: false,                              // disable generation of arrow mark-up
	    dropShadows: false                              // disable drop shadows
	}); 
	
	$('#slideshow').cycle({
		speed:  2000,		
	    speed:  500,
	    timeout: 6000,
	    pager:  '#pager',
	    pause: true,
	    pagerAnchorBuilder: function(idx, slide) {
	        // return sel string for existing anchor
	        return '#pager li:eq(' + (idx) + ') a';
	    }
	
	});
	
	if($("#search #query").length) {
		if($("#search #query").val() == '') {
			$("#search #query").val('Search');
		}
		$("#search #query").focus(function(){
			if (this.value == 'Search') {
				this.value='';
			}
		});
		
		$("#search #query").blur(function(){
			if (this.value == '') {
				this.value='Search';
			}
		});
	}
	
	$('.commentForm').hide();
	
	$('.addComment').click(function(){
		$('.commentForm').slideToggle('fast');
		$(this).hide();
		return false;		
	});
	
	$('.submitBtn.comment').submit(function(){
		$('.commentForm').hide();
		$('.addComment').show();
		return false;		
	});
	
	$('.cancelComment').click(function(){
		$('.commentForm').hide();
		$('.addComment').show();
		return false;		
	});
	
	$("#blog_archives, #news_archives").change(function() {
		if($(this).val() != "") {
			window.location = $(this).val();
		}
	});
	
	$('.pause').click(function() { $('.slides').cycle('pause'); return false; });
    $('.play').click(function() { $('.slides').cycle('resume'); return false; });
	
	$("#controls, .fullSizeSlideshow").hide();
    
    $('.slideshow').hover(
        function() { $('#controls').fadeIn(); },
        function() { $('#controls').fadeOut(); }
    );
    
    $('.slides').cycle({
        fx:     'fade',
        speed:   400,
        timeout: 5000,
        next:   '.next',
        prev:   '.prev'
    });
        
	$('form[name="star_rating"]').ajaxForm({ success: confirmStarRating });
	
	$(".starRating").stars({
		oneVoteOnly: true,
		inputType: "select",
		callback: function(ui, type, value)
		{
			//return false;
			$('form[name="star_rating"]').submit();
		}
	});
	
	
    
    $(function () {
            var tabContainers = $('div.tabs > div');
            tabContainers.hide().filter(':first').show();
            
            $('div.tabs ul.tabNavigation a').click(function () {
                    tabContainers.hide();
                    tabContainers.filter(this.hash).show();
                    $('div.tabs ul.tabNavigation a').removeClass('selected');
                    $(this).addClass('selected');
                    return false;
            }).filter(':first').click();
    });
    
    $('.favorites a, .favoritesRemove a') .click (function() {
		var caller = $(this);
		$.get(this.href, function(data) {
			data = $.trim(data);
			var count = 0;
			var link = $(caller).attr("href");
			var text = $(caller).text();
			text = $.trim(text);
			count = text.substring(11,text.length-1);
			
			if(data == "added") {
				count++;
				$(caller).parent().removeClass('favorites').addClass('favoritesRemove');
				$(caller).attr("href", link+'delete/');
				$(caller).text('Favorites ('+count+') ');
			} else if (data == "deleted") {
				count--;
				$(caller).parent().removeClass('favoritesRemove').addClass('favorites');
				$(caller).attr("href", link.substring(0, link.length-7));
				$(caller).text('Favorites ('+count+') ');
			} else {
				alert(data);
			}
		});
		return false;
	});
     
    
    $("a[rel='slideshow1']").colorbox({initialWidth:100, initialHeight:100, maxWidth:"90%", maxHeight:"90%"});
    
    $(".createAccount").colorbox({width:"550px", height:"650px", inline:true, href:"#registration", transition:"none"});
    
    $(".emailThis").colorbox({width:"480px", height:"490px", inline:true, href:"#email_this", transition:"none"});
    
   	setTimeout(function(){
  		$(".success").fadeOut("slow", function () {
  			$(".success").remove();
      	});

		}, 3000);
	
	$(".lockedLogin").click(function() { 
 
        // perform exposing for the clicked element 
        $("#loginInner").expose({
        	api: true,
            onBeforeLoad: function() { 
        		$("#loginInner").animate({ right: "200px", top: "60px" }, 600 ).css({background: 'url(/images/loginInner_bg.png) no-repeat center center', padding: '40px 32px 32px 32px'}); 
    		},
    	    onClose: function() { 
        		$("#loginInner").animate({ right: "0", top: "0" }, "fast" ).css({background: 'none', padding:'8px 0 0 0'}); 
    		}
        }).load(); 
    });	
});
