
function checkForm(obj, callback){
    var error = false;
    
    // Check required fields
    jQuery(obj).find('.required').each(function(index, obj){
        if (!obj.value || obj.value == obj.title) {
            error = true;
            alert('Please fill all required fields!');
            jQuery(obj).focus();
            return false;
        }
    });
    
    if (!error && callback) {
        callback(obj);
        return false;
    }
    
    return error ? false : true;
}

function subscribePost(obj)
{
	jQuery.post( '/signup?ajax=1', jQuery(obj).serialize(), function(data){
		if( data == '0' ){
			alert('An error occured. Please try again later.');
		} else {
			window.open( data );
			NewsletterPopup.Close(NewsletterPopup);
		}
	});
}

function joinGuestlist(obj)
{
	jQuery.post( '/join?ajax=1', jQuery(obj).serialize(), function(data){
		if( data != '1' ){
			alert('An error occured. Please try again later.');
		} else {
			alert('You are on the list!');
			EventGuestlist.Close(EventGuestlist);
		}
	});
}

function joinGuestlistFriends(obj)
{
	jQuery.post( '/join?ajax=1', jQuery(obj).serialize(), function(data){
		if( data != '1' ){
			alert('An error occured by the following person(s):'+"\n"+data);
		} else {
			alert('Your friends are on the list!');
			InvitePopup.Close(InvitePopup);
		}
	});
}

function openGallery(obj,href)
{
	if( !href ){ href = obj.href; }
	
	jQuery('#fb_redirect_url').val( href );
	jQuery('#popup-newsletter h3').html('Please enter the following information<br/>to view our galleries.');	
	
	document.getElementById('popup-newsletter-close').onclick = function(){
		window.open(href);
		NewsletterPopup.Close(NewsletterPopup);
	};
	
	NewsletterPopup.Open();
}

function openEvent(obj,href)
{
	jQuery('#fb_redirect_url').val( href );
	jQuery('#popup-newsletter h3').html('Please enter the following information<br/>to view our event details.');
			
	document.getElementById('popup-newsletter-close').onclick = function(){
		window.open(href);
		NewsletterPopup.Close(NewsletterPopup);
	};
	NewsletterPopup.Open();
}

function joinEvent(obj,event_id,event_img,event_title,event_date)
{
	jQuery('#fb_event_id').val( event_id );
	jQuery('#fb_event_id_friends').val( event_id );
	jQuery('#event-img').attr( 'src', event_img );
	jQuery('#event-title').html( event_title );
	jQuery('#event-date').html( event_date );
		
	document.getElementById('popup-guestlist-close').onclick = function(){		
		EventGuestlist.Close(EventGuestlist);
	};
	
	EventGuestlist.Open();
}

jQuery(document).ready(function(){

    current_index = jQuery(".top_menu_sec .current-menu-item").index();
    
    jQuery(".content .top_text_menu_container ul li:eq(" + current_index + ")").each(function(){
    
        jQuery(this).append('<img src="' + template_url + '/images/menu_arrow.png" alt="SD Social Menu Arrow" />');
        
    });
    
    jQuery(".content .top_text_menu_container ul li:eq(" + current_index + ")").each(function(){
    
        jQuery(this).css("visibility", "visible");
        
    });
    
    
    jQuery(".top_text_menu_container:eq(0)").each(function(){
    
        max_menu_num = jQuery(this).children("ul").children("li").size() - 1;
        jQuery(this).children("ul").children("li:eq(" + max_menu_num + ")").css("borderRight", "none");
        
    })
    
    jQuery(".footer_vertical_menu .resizer").each(function(){
    
        max_menu_num = jQuery(this).children("ul").children("li").size() - 1;
        jQuery(this).children("ul").children("li:eq(" + max_menu_num + ")").css("borderRight", "none");
        
    })
    
    jQuery(".top_text_menu_container li:eq(0)").css("paddingLeft", "0px");
    
    
    
    
    jQuery(".right_sidebar .simple_box_sidebar:eq(0)").css("marginTop", "0px");
    
    
    jQuery(".calendar .day.event").mouseover(function(){
    
        jQuery(this).children(".event_sign").css("display", "none");
        jQuery(this).children(".event_info_arrow").css("display", "");
        
        position = jQuery(this).position();
        jQuery(this).siblings(".event_details").css("display", "");
        new_top = position.top - 272;
        jQuery(".event_details").css("top", new_top + "px");
        
        classes = jQuery(this).attr("class").split(" ");
        id = classes[2].replace("event_id_", "");
        jQuery("#event_data_" + id).css("display", "inherit");
        
        jQuery(this).children("a").css("color", "#ffffff");
        jQuery(this).children("a").css("backgroundColor", "#848484");
        
    });
    
    jQuery(".calendar .day.event").mouseout(function(){
    
        jQuery(this).children(".event_sign").css("display", "");
        jQuery(this).children(".event_info_arrow").css("display", "none");
        jQuery(this).siblings(".event_details").css("display", "none");
        
        classes = jQuery(this).attr("class").split(" ");
        id = classes[2].replace("event_id_", "");
        jQuery("#event_data_" + id).css("display", "none");
        
        jQuery(this).children("a").css("color", "#848484");
        jQuery(this).children("a").css("backgroundColor", "#ffffff");
        
    });
    
    jQuery(".calendar .day.event").click(function(){
    
        document.location.href = jQuery(this).children("a").attr("href");
        
    });
    
    
    
    jQuery(".event_info_arrow").css("display", "none");
    jQuery(".event_details").css("display", "none");
    
    try {
    
        calendar_moving_container_width = jQuery(".calendar .moving_container .month_holder").size() * jQuery(".calendar .moving_container .month_holder").css("width").replace("px", "");
        jQuery(".calendar .moving_container").css("width", calendar_moving_container_width + "px");
        
    } 
    catch (e) {
    
    }
    
    
    
    jQuery(".month_holder:eq(0) .header .left_arrow").css("display", "none");
    jQuery(".month_holder:eq(" + (jQuery(".month_holder").size() - 1) + ") .header .right_arrow").css("display", "none");
    
    jQuery(".month_holder .header .left_arrow").click(function(){
    
        current_margin = jQuery(".calendar .moving_container").css("marginLeft").replace("px", "");
        new_margin = parseInt(current_margin) + 280;
        
        jQuery(".calendar .moving_container").animate({
            marginLeft: new_margin + 'px'
        }, 1000);
        
        
    });
    
    
    jQuery(".month_holder .header .right_arrow").click(function(){
    
        current_margin = jQuery(".calendar .moving_container").css("marginLeft").replace("px", "");
        new_margin = parseInt(current_margin) - 280;
        
        
        jQuery(".calendar .moving_container").animate({
            marginLeft: new_margin + 'px'
        }, 1000);
        
        
    });
    
    
    jQuery(".top_menu_sec .resizer .event_selector .event_helper:eq(0)").each(function(){
    
    
    
        jQuery(this).css("display", "inherit");
        
        
        
        
        jQuery(".g_a").each(function(){
        
            current = jQuery(this);
            
            jQuery(this).parents(".rela.clickable").click(function(){
            
                index = jQuery(this).parents(".rela.event_helper").index();
                
                link = jQuery(".g_a:eq(" + index + ")").attr("href");
                document.location.href = link;
                
            })
            
            
            
            
        });
        
        
    });
    
    jQuery(".next_event").click(function(){
    
    
        current_event = 0;
        
        max_event = jQuery(".top_menu_sec .resizer .event_selector .event_helper").size();
       	
        jQuery(".top_menu_sec .resizer .event_selector .event_helper").each(function(){
        
            if (jQuery(this).css("display") == "inherit") {
            
                current_event = jQuery(this).index();
                current_event++;
                if (current_event == max_event) 
                    current_event = 0;
                
                jQuery(this).css("display", "none");
                
            }
            
        });
        
        jQuery(".top_menu_sec .resizer .event_selector .event_helper:eq(" + current_event + ")").css("display", "inherit");
        
    });
    
    
    
    jQuery(".content .event_info form input[type=text]").focus(function(){
    
        jQuery(this).siblings("label").hide();
        
        
    });
    
    jQuery(".content .event_info form input[type=text]").blur(function(){
    
    
        if (jQuery(this).val().replace(" ", "") == "") 
            jQuery(this).siblings("label").show();
        
        
    });
    
    
    jQuery(".content .event_info form input[type=text]").each(function(){
    
        if (jQuery(this).val().replace(" ", "") == "") 
            jQuery(this).siblings("label").css("visibility", "visible");
        
    });
    
    
    
    
    jQuery(".tab_content").hide();
    jQuery(".tab_content:eq(0)").show();
    
    
    jQuery(".tab").click(function(){
    
        jQuery(".tab").removeClass("active");
        jQuery(this).addClass("active");
        
        index = jQuery(this).index();
        
        jQuery(".tab_content").hide();
        jQuery(".tab_content:eq(" + index + ")").show();
        
    });
    
    
    jQuery("#gallery_search_from").datepicker({
        onSelect: function(dateText, inst){
        
            jQuery(this).siblings("label").hide();
            
        }
    });
    
    jQuery("#gallery_search_until").datepicker({
        onSelect: function(dateText, inst){
        
            jQuery(this).siblings("label").hide();
            
        }
    });
    
    jQuery("#gallery_search input[type=text]").blur(function(){
    
    
        if (jQuery(this).val() != "") 
            jQuery(this).siblings("label").hide();
        if (jQuery(this).val() == "") 
            jQuery(this).siblings("label").show();
        
    })
    
    jQuery("#gallery_search input[type=text]").focus(function(){
    
    
        jQuery(this).siblings("label").hide();
        
    })
    
    
    jQuery("#gallery_search input[type=text]").keyup(function(){
    
    
        if (jQuery(this).val() != "") 
            jQuery(this).siblings("label").hide();
        if (jQuery(this).val() == "") 
            jQuery(this).siblings("label").show();
        
    })
    
    jQuery("#gallery_search input[type=text]").each(function(){
    
    
        if (jQuery(this).val() != "") 
            jQuery(this).siblings("label").hide();
        if (jQuery(this).val() == "") 
            jQuery(this).siblings("label").show();
        
    })
    
    
    
    
    
    
    fix_flash();
    
    
    jQuery("#image_holder img:eq(0)").css("display", "block");
    
    
    jQuery("#controller img").click(function(){
    
        i = jQuery(this).parent("div").index();
        jQuery("#image_holder img").fadeOut(1000);
        jQuery("#controller img").css("display", "block");
        jQuery("#image_holder img:eq(" + i + ")").fadeIn(1000);
        
    });
    
    
    sum_of_widths = 0;
    
    jQuery("#thumb_holder div").each(function(){
    
        sum_of_widths = jQuery(this).width() + sum_of_widths + 22;
        
    });
    
    jQuery("#thumb_holder").width(sum_of_widths);
    
    carousel_position = 0;
    
    jQuery("#controller .left_button").hide();
	
	if( jQuery("#thumb_holder div").size() < 5 ){
		jQuery("#controller .right_button").hide();
	}
    
    jQuery("#controller .right_button").click(function(){
    
        carousel_position--;
        move = (sum_of_widths / jQuery("#thumb_holder div").size() - 1) * carousel_position;
        jQuery("#thumb_holder").animate({
            marginLeft: move + "px"
        }, 1000);
        
        if( jQuery("#thumb_holder div").size() < 5 || (carousel_position == -jQuery("#thumb_holder div").size() + 4) ) 
            jQuery("#controller .right_button").hide();
        else 			
            jQuery("#controller .right_button").show();
        
        if (carousel_position == 0) 
            jQuery("#controller .left_button").hide();
        else 
            jQuery("#controller .left_button").show();
        
    });
    
    jQuery("#controller .left_button").click(function(){
    
        carousel_position++;
        move = (sum_of_widths / jQuery("#thumb_holder div").size() - 1) * carousel_position;
        jQuery("#thumb_holder").animate({
            marginLeft: move + "px"
        }, 1000);
        
        if (carousel_position == -jQuery("#thumb_holder div").size()) 
            jQuery("#controller .left_button").hide();
        
        
        if (carousel_position == 0) 
            jQuery("#controller .left_button").hide();
        else 
            jQuery("#controller .left_button").show();
        
        if (carousel_position == -jQuery("#thumb_holder div").size() + 4) 
            jQuery("#controller .right_button").hide();
        else 
            jQuery("#controller .right_button").show();
        
        
        
    });
    
    
    
});




function fix_flash(){
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i)) 
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else 
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        }
        else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window') 
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i)) 
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else 
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                } 
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
    
    
    
}

