$(document).ready(function() {

    if ($('input[name=mobile_opt_in]').attr('checked')) {
        $('#extra_fields').show();
    }

    if ($('input[name=email_opt_in]').attr('checked')) {
        $('#extra_fields').show();
    }

    $('input[name=mobile_opt_in]').click(function() {
        if ($(this).attr('checked')) {
            $('#extra_fields').show();
        } else if ($('input[name=email_opt_in]').attr('checked') == false) {
            $('#extra_fields').hide();
        }
    });

    $('input[name=email_opt_in]').click(function() {
        if ($(this).attr('checked')) {
            $('#extra_fields').show();
        } else if ($('input[name=mobile_opt_in]').attr('checked') == false) {
            $('#extra_fields').hide();
        }
    });

    $('a[rel=external]').click(function() {
        alert("You are now leaving VOXVodka.com. Please remember that we are not responsible for content outside of our site.")
        window.open(this.href);
        return false;
    });

    $('a[rel=new_window]').click(function() {
        window.open(this.href);
        return false;
    });

    // ShareThis Alert
    /*$('.stbuttontext').hover(function(){
    var answer = confirm("You have selected to Share Jim Beam content, please do not share with individuals under 21 years of age.")
    if (answer){
    $('.stframe').show();
    }
    else{
    $('.stframe').hide();
    }
    }); */

    $("#main_content_container .more").click(function() {
        if ($('#' + this.id + '_full').is(':hidden')) {
            $('.fullDetail').slideUp();
            set_blkLinks('More &raquo;');
            $(this).html('Less &raquo;').val();
        } else {
            $(this).html('More &raquo;').val();
        }
        $('#' + this.id + '_full').slideToggle();
    });

    //if submit button is clicked  
    $("#submit_comment").click(function() {

        //Get the data from all the fields  
        var recipe_id = $('input[name=RecipeID]');
        var user_id = $('input[name=UserID]');
        var rating = $('input[name=Rating]:checked');
        var comment = $('textarea[name=Comment]');

        var message = "";
        // Check for null comment fields
        if (recipe_id.val() == '') {
            message += '\tRecipe ID cannot be blank\n';
        }

        if (user_id.val() == '') {
            message += '\tYou must be logged in to submit a rating/comment\n';
        }

        if (rating.val() == undefined || rating.val() == '') {
            message += '\tPlease select a rating for this recipe\n';
        }

        if (message) {
            alert('Your comment could not be accepted because:\n\n' + message + '\nPlease correct the problem and resubmit.');
            return false;
        }

        //show the loading sign  
        //$('.loading').show(); 

        $('#comment_result').load('/mixology/comment', { RecipeID: recipe_id.val(), UserID: user_id.val(), Rating: rating.val(), Comment: encodeURIComponent(comment.val()) });

        return false;


    });

});

var set_blkLinks = function (content){
	$("#main_content_container .more").each(function(){
		$(this).html(content).val();
	});
}

var set_content = function(selector, content){
	$(selector).html(content);
	return false;
}

var do_pop_up = function(name, width, height) {
    window.open(name, "t", "menubar=0,width=" + width + ",height=" + height + ",toolbar=0,resizable=0,location=0,scrollbars=1");
    return false;
}
			
function formatSearchQuery() {
	if(document.search_form.query.value != "") {
		var query_string = document.search_form.query.value.replace(/ /g, "+");
		document.search_form.action += query_string + "/";
		return true;
	}
	else {
		alert('Please enter a search query');
		return false;
	}
}   

function clearSearch(searchBox)
{
	if (searchBox.value == 'Search')
		searchBox.value = '';
}

///// SIDEBAR PANELS
function OpenClose(i) 
{
	var PM = document.getElementById("PM" + i);
	var SB = document.getElementById("SB" + i);
	
	if (PM.innerHTML == "-") {
		PM.innerHTML = "+";
		$(SB).slideUp("slow");
		//SB.style.display = "none";
	}
	else {
		PM.innerHTML = "-";
		$(SB).slideDown("slow");
		//SB.style.display = "block";	
	}
} 

////// TABS
var track = 1;

function TabChange(i) {
	var button = document.getElementById("B" + i);
	var tab = document.getElementById("T" + i);
	var buttonLast = document.getElementById("B" + track);
	var tabLast = document.getElementById("T" + track);
	
	//alert("Last " + track + ", Current " + i );

	//AJAX call for Omniture Analytics 
     //nulled out call to wirestone analytics in s=s_gi("");
     //var s=s_gi('');
     //s.prop3="AJAX Tab:" + button.title;
     //s.tl('test','o',button.title);
     //End AJAX
    
	track = i;

	buttonLast.className = "tabOff";
	tabLast.style.display = "none";
	
	button.className = "tabOn";
	tab.style.display = "block";
}
