// Initialize main navigation drop down
$(document).ready(function() {
    $('#nav-main ul').superfish({
        delay: 250,
        animation: { height: 'show' },
        speed: 'normal',
        autoArrows: false,
        dropShadows: false
    });
});

// Clear form titles on focus. Reapply if nothing was typed in.
$(document).ready(function() {
    $("input").focus(function() {
        if ($(this).val() === $(this).attr("title")) {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() === "") {
            $(this).val($(this).attr("title"));
        }
    });
});

// Slider script
$(document).ready(function() {
	$("#myController, #myController-thumb").jFlow({
		slides: "#slides",  // the div where all your sliding divs are nested in   
		controller: ".jFlowControl", // must be class, use . sign   
		slideWrapper: "#jFlowSlide", // must be id, use # sign   
		selectedWrapper: "jFlowSelected",  // just pure text, no sign   
		width: "723px",  // this is the width for the content-slider   
		height: "297px",  // this is the height for the content-slider   
		duration: 400,  // time in miliseconds to transition one slide   
		prev: ".jFlowPrev", // must be class, use . sign
		next: ".jFlowNext", // must be class, use . sign
		auto: true
	});

    //call the jQuery Hover Over and Out
    $('#btnPrev').hover(overPrev, outPrev);
    //Tell the browser to change the background when hovered over
    function overPrev(event) {
        $(this).css("background", "url('/images/slider-btn-left-sprite.png') 0 57px");
        $(this).css("cursor", "pointer");
    }
    //tell the browser to change the background to nothing when 
    //going outside the object area
    function outPrev(event) {
        $(this).css("background", "url('/images/slider-btn-left-sprite.png') 0 0");
    }
    $('#btnNext').hover(overNext, outNext);
    //Tell the browser to change the background when hovered over
    function overNext(event) {
        $(this).css("background", "url('/images/slider-btn-right-sprite.png') 0 57px");
        $(this).css("cursor", "pointer");
    }
    //tell the browser to change the background to nothing when 
    //going outside the object area
    function outNext(event) {
        $(this).css("background", "url('/images/slider-btn-right-sprite.png') 0 0");
    }
});

// Explore our Decor
$(document).ready(function() {
    function hoverHotSpotOver() {
        $(this).css('background-position', '0 -18px');
        maxX = 315;
        maxY = 91;
        minY = 0;
        var hotspotPosition = $(this).position();
        hotboxTop = hotspotPosition.top - 103;
        if (hotboxTop > maxY) {
            hotboxTop = maxY;
        } else if (hotboxTop < minY) {
            hotboxTop = minY;
        } else {
            hotboxTop = hotboxTop;
        }
        if (hotspotPosition.left > 361) {
            hotboxLeft = hotspotPosition.left - 389;
        } else {
            hotboxLeft = hotspotPosition.left;
        }
        $(this).next('.hotbox').css({ 'top': hotboxTop + 'px', 'left': hotboxLeft + 'px' });
        $(this).next('.hotbox').addClass('extendHover').show();

        //$(this).children('a').css("background-position","0 -56px");
    }
    function hoverHotSpotOut() {
        $(this).next('.hotbox').mouseleave(function() {
            $(this).removeClass('extendHover');
            if (!($(this).next('.hotbox').hasClass('extendHover'))) {
                $(this).hide();
                $(this).prev().css('background-position', '0 0');
            }
        });



    }
    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
        interval: 50, // number = milliseconds for onMouseOver polling interval
        over: hoverHotSpotOver, // function = onMouseOver callback (REQUIRED)
        timeout: 0, // number = milliseconds delay before onMouseOut
        out: hoverHotSpotOut // function = onMouseOut callback (REQUIRED)
    };
    $(".slide-wrapper .hotspot").hoverIntent(config);
});


// tabs
$(document).ready(function() {
    $('#tabs-wrapper').tabs({ selected: 0 });
    $('#tabs-wrapper #controls li').click(function() {
        $(this).addClass('active');
        $(this).siblings('li').removeClass('active');
    });

    // album details page
    $('#album').tabs({ selected: 0 });
    $('#video').tabs({ selected: 0 });
/*
    $('.video-controls ul li a').click(function() {
        $('.video-controls ul li a').css('border-bottom', '1px dotted #bfb39a');
        $('.video-controls ul li.last a').css('border-bottom', 'none');
        $(this).parent('li').prev('li').children('a').css('border-bottom', '1px solid #fff3d2');
        $(this).css('border-bottom', '1px solid #fff3d2');
    });
*/
});

//Original code just in case
/*$(document).ready(function(){
$('#tabs-wrapper').tabs({ selected:0 });
$('#tabs-wrapper #controls li').click(function() {
$(this).addClass('active');
$(this).siblings('li').removeClass('active');
});
});

$(document).ready(function(){
$('#tabs-wrapper').tabs({ selected:0 });
$('#album').tabs({ selected:0 });
$('#video').tabs({ selected:0 });
$('.video-controls ul li a').click(function() {
$('.video-controls ul li a').css('border-bottom', '1px dotted #bfb39a');
$('.video-controls ul li.last a').css('border-bottom', 'none');
$(this).parent('li').prev('li').children('a').css('border-bottom', '1px solid #fff3d2');
$(this).css('border-bottom', '1px solid #fff3d2');
});
});*/

// Categories for music
$(document).ready(function() {
    allGenres = $('.promos .block');
    $('#controls li').first().addClass('active');
    $('#controls li').click(function() {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
        category = $(this).children('a').html();
        genre = '.promos .' + category;
        if (category != 'All Genres') {
            $('.promos .block').not('.' + category).hide();
            $(genre).show()
        } else {
            $(allGenres).show();
        }
    });
});

// FAQs page
$(document).ready(function() {
    $('#faqs p').css('display', 'none');
    $('#faqs li').click(function() {
        if ($(this).is('.active')) {
            $(this).children('p').slideUp('fast');
            $(this).children('span.plus-minus').css('background-position', '0 0');
            $(this).removeClass('active');
        } else {
            $(this).addClass('active');
            $(this).children('p').slideDown('fast');
            $(this).children('span.plus-minus').css('background-position', '-22px 0');
        }
    });
});

// Launch tour
$(document).ready(function() {

    // initialize colorbox
    $(".launch-tour").colorbox({
        inline: true,
        href: "#virtual-tour",
        opacity: 0.5,
        overlayClose: false,
        scrolling: false,
        transition: 'none',
        onOpen: function() {
            $('#virtual-tour').css('display', 'block');
        },
        onLoad: function() {
            $('#cboxClose').addClass('virtual-tour');
			// VIRTUAL TOUR
				if (swfobject.hasFlashPlayerVersion("9")) {
					var flashEmbed = '<p class="intro">To explore, just left-click on the video and drag your mouse left and right.</p><div class="shadow-one"><div class="corner-a"></div><div class="corner-b"></div><div class="shadow-two"><div class="shadow-three"><div class="shadow-four"><div id="myAlternativeContent"></div></div></div></div></div><div class="clr"></div><h3><strong>Directions: </strong><br />Click on the "+" signs to find out more! To jump to a new location, click on "Porch,""Restaurant," or "Store" and to zoom in and out, use the "+/-". If you get tired,click on "Auto View" and let us take you for a spin!</h3>';
					$("#virtual-tour-inner").html(flashEmbed);
					
					var att = { data:"/flash/cb_360/cb_360.swf", width:"640", height:"322" };
					var par = { 
						menu:"false", 
						allowfullscreen:"true",
						flashvars: "xmlData=/flash/cb_360/xml/videoList.xml"
					};
					var id = "myAlternativeContent";
					var myFlashContent = swfobject.createSWF(att, par, id);
				} else {
						var quicktimeMP4Embed = "<div class='shadow-one'><div class='corner-a'></div><div class='corner-b'></div><div class='shadow-two'><div class='shadow-three'><div class='shadow-four'><div id='myAlternativeContent'><object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='640' height='378' controller='true' codebase='http://www.apple.com/qtactivex/qtplugin.cab'><param name='SRC' value='http://c592098.r98.cf2.rackcdn.com/cb_director_cut.mp4' /><param name='AUTOPLAY' value='true' /><param name='CONTROLLER' value='true' /><embed src='http://c592098.r98.cf2.rackcdn.com/cb_director_cut.mp4' width='640' height='378' autoplay='true' controller='true' pluginspage='http://www.apple.com/quicktime/download/'></embed></object></div></div></div></div></div><div class='clr'></div>";
						$("#virtual-tour-inner").html(quicktimeMP4Embed);
				}
			// END VIRTUAL TOUR
        },
        onCleanup: function() {
            $('#virtual-tour').css('display', 'none');
        }
    });
});

// Quiz
$(document).ready(function() {

    // initialize colorbox
    $(".start-quiz").colorbox({
        inline: true,
        href: "#quiz",
        opacity: 0.5,
        overlayClose: false,
        scrolling: false,
        transition: 'none',
        onOpen: function() {
            $('#quiz').css('display', 'block');
        },
        onLoad: function() {
            $('#cboxClose').addClass('quiz');
        },
        onCleanup: function() {
            $('#quiz').css('display', 'none');
        }
    });

    // initialize variables
    position = 0;
    score = 0;
    xCoor = 0;
    yCoor = 0;

    // display the first question
    $('#quiz .group').first().css('display', 'block');

    // add our buttons
    $('.group').each(function() {
        $(this).find('.choices li').append('<a>Select</a>');
        $(this).find('.correct-answer, .wrong-answer').append('<a>Next Question</a>');
    });

    // make things happen when question is answered
    $('.choices li a').click(function() {
        myIndex = $(this).parents('.group').index();
        if ($(this).parent('li').is('.correct')) {
            $(this).parents('.question').hide();
            $(this).parents().siblings('.correct-answer').show();
            score++;
        } else {
            $(this).parents('.question').hide();
            $(this).parents().siblings('.wrong-answer').show();
        }
    });

    // add our numbers
    $('#question-number').prepend('<ul>').end().append('</ul>');
    $('#quiz .group').each(function(i) {
        $('#question-number ul').append('<li>').end().append('</li>');
    });

    $('#question-number ul li').each(function(e) {
        xCoor = e * 20;
        $(this).css('background-position', -xCoor + 'px 0px');
    });

    // Make sure the first number is selected on load
    $('#question-number ul li').first().addClass('selected');
    // Go to the next question or display the end
    $('.correct-answer a, .wrong-answer a').click(function() {
        $('#question-number ul li').eq(myIndex + 1).addClass('selected').end().eq(myIndex).removeClass('selected');
        $(this).parents('.group').hide().end().parents('.group').next('.group').show();
        if (!$(this).parents('.group').next('.group').length) {
            if (score <= 3) { congrats = "Nice try, but you have to brush up on your knowledge of Americana!"; }
            if ((score >= 4) && (score <= 6)) { congrats = "A great effort! Your Americana knowledge is a-okay!"; }
            if (score >= 7) { congrats = "Excellent job! You definitely know your Americana inside and out!"; }
            $('#quiz #finish').show();
            $('#quiz #finish').prepend('<h3>Nice Work</h3><p>You scored ' + score + ' out of ' + $('#quiz .group').length + '</p><p>' + congrats + '</p>');
        }
    });

    $('a.reset').click(function() {
        $('#quiz .group').css('display', 'none');
        $('#quiz .group').children().css('display', 'none');
        $('#quiz .group').children('.question').show();
        $('#quiz .group').children('.image').show();
        $('#quiz .group').first().css('display', 'block');
        $('#quiz .group').first().find('.question').show();
        $('#quiz .group').first().find('.image').show();
        $('#quiz #finish').hide();
        $('#quiz #finish .facebook-share').prev().remove().end().prev().remove().end().prev().remove();
        position = 0;
        score = 0;
        xCoor = 0;
        yCoor = 0;
        return false;
    });
});

// Restoration Step-by-Step
$(document).ready(function() {
    $('#step-by-step').tabs({ selected: 0 });
    $('#step-by-step ol li').append('<span class="tab-hover"></span>');
    var $tabs = $('#step-by-step').tabs();
    $('#sliderContainer a.prev, #sliderContainer a.next').click(function() { return false; });
    $('a.next').click(function() {
        var selected = $tabs.tabs('option', 'selected');
        $tabs.tabs('select', selected + 1);
    });
    $('a.prev').click(function() {
        var selected = $tabs.tabs('option', 'selected');
        $tabs.tabs('select', selected - 1);
    });
});

function BlogArchiveSelected(dropdown) {
    var myindex = dropdown.selectedIndex;
    if (myindex != 0) {
        var SelValue = dropdown.options[myindex].value;
        var date = SelValue.split("|");
        var month = date[0];
        var year = date[1];
        location.href = "?month=" + month + "&year=" + year;
    }
}

//Flash Radio
var songNumVar;
var songPostionVar;
var albumName;
var albumArt;
var artistName;
var songName;
var recentlyPlayedNum = 5;
var songCount;
var removeSongNum;
var albumLink;
var artistProfileLink;
var songClip;

function addRecentlyPlayed(albumName, artistName, songName, songCount, albumArt, albumLink, artistProfileLink, songClip) {
    if (songCount > recentlyPlayedNum) {
        removeSongNum = songCount - recentlyPlayedNum;
        $("#recently-played ul li#song_" + removeSongNum).remove();
    }
    $("#recently-played ul").removeClass("first");
    var recentlyPlayedElement = "<li id='song_" + songCount + "'><span class='shadow-album'><img src='" + albumArt + "' alt='' width='51px' height='46px' /></span><div class='info-wrapper'><div class='info'><h6>Artist</h6><a href='" + artistProfileLink + "' class='text'>" + artistName + "</a></div><div class='info'><h6>Song</h6><span class='text'>" + songName + "</span></div><div class='info'><h6>Album</h6><a href='" + albumLink + "' class='text'>" + albumName + "</a></div><div class='clearfix'></div></div><p><a href='" + songClip + "' class='sm2_button'>TEST</a></p><div class='clearfix'></div></li>"
    $("#recently-played ul").prepend(recentlyPlayedElement);
	soundManager.reboot();
	$(".sm2_button").innerHTML = "";
}

function popupPlayer(songNum, songPosition) {
    songNumVar = songNum;
    songPositionVar = songPosition;
    window.open("/music/radio-player-popup.html", "myWindow", "status = 1, height = 237, width = 789, resizable = 1");
    return (songNum);
}
function getSongNum() {
    return -1;
}
function getSongPosition() {
    return -1;
}
function changeText(videoLocation) {
    return (videoLocation);
}
//END RADIO PLAYER

// CLIP AUDIO PLAYER
soundManager.url = '/flash/clip-player/';
soundManager.debugMode = false;
//END CLIP AUDIO PLAYER

// YOUTUBE VIDEO SUPPORT FOR MUSIC PAGE
$(document).ready(function(){

	function getYoutubeVars(URL) {
		var vars = [], hash;
		var hashes = URL.slice(URL.indexOf('?') + 1).split('&');
		for (var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}

	$("<div class='youtube-wrapper'></div>").appendTo(".tab-inner");
	$(".youtube-wrapper").css({"display" : "none", "background" : "url('/images/music_video_player_bg.png') no-repeat scroll 0 0 transparent", "margin" : "-6px 0 0", "padding" : "4px 0 6px 5px", "width" : "460px"});
	
	//$(".changeMovie[rel*='youtube']").removeAttr("href");
	//$(".changeMovie[rel*='youtube']").attr("href", "#tabs-inner");
	$(".changeMovie[rel*='youtube']").css("cursor", "pointer");
	
	
	var youtubeURL = "http://www.youtube.com/watch?v=";
		if ($(".firstMovie[rel*='youtube']").html() != null){
			$(".youtube-wrapper").empty();
			$(".youtube-wrapper").css("display", "block");
			
			if ($(".firstMovie").attr("rel").toString().search(youtubeURL)){
				
				var youtubeID = getYoutubeVars($(".firstMovie").attr("rel").toString());
				youtubeID = youtubeID["v"];
				
				$(".video-wrapper").css("display", "none");
				$(".youtube-wrapper").append("<iframe width='449' height='335' src='http://www.youtube.com/embed/" + youtubeID + "' frameborder='0' allowfullscreen></iframe>");
			}
		}
	
	$(".changeMovie[rel*='/videos/']").click(function(){
		
		$(".youtube-wrapper").empty();
		$(".youtube-wrapper").css("display", "none");
		$(".video-wrapper").css("display", "block");
	});
	
	$(".changeMovie[rel*='youtube']").click(function(){
	
		$(".youtube-wrapper").empty();
		$(".youtube-wrapper").css("display", "block");
		
		if ($(this).attr("rel").toString().search(youtubeURL)){
			
			var youtubeID = getYoutubeVars($(this).attr("rel").toString());
			youtubeID = youtubeID["v"];
			
			$(".video-wrapper").css("display", "none");
			$(".youtube-wrapper").append("<iframe width='449' height='335' src='http://www.youtube.com/embed/" + youtubeID + "' frameborder='0' allowfullscreen></iframe>");
		}
	});
});

// Form selects
$(document).ready(function() {
    $(".form-block SELECT").selectBox()
    $(".block SELECT").selectBox()
});

function emailValidate(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false) {
        return false;
    }
}

var movieFile;
function initialLoadFile() {
        return movieFile;
    }
	
$(document).ready(function() {

    //Music Video Player
    
    $(document).ready(function() {
		$("a[href='#video']").click(function(){

			var flashvars = {
			};
			var params = {
				wmode: "transparent",
				allowScriptAccess: "sameDomain"
			};
			var attributes = {};
			attributes.id = "videoPlayer";
			swfobject.embedSWF("/flash/videoPlayer.swf", "videoPlayerContainer", "449", "337", "9.0.0", false, flashvars, params, attributes);
			

		});
	
        movieFile = $(".firstMovie").attr("rel");

        $(".changeMovie").click(function() {
            movieFile = $(this).attr("rel");
            sendTextToAS3(movieFile);
        });

        function sendTextToAS3(movieName) {
            var Txt = movieName;
            var flash = document.getElementById("videoPlayer");
            flash.sendTextFromJS(Txt);
        }

    });
    //END Video Player	
    $('a.changes').click(function() {
        $.colorbox.close();
    });

//    $('.max-len-blog').keyup(function() {
//        var len = $(this).val().length;
//        if (len >= 500) {
//            this.value = this.value.substring(0, 500);
//        }
//    });

    $('.max-len-blog').keyup(function() {
        var len = $(this).val().length;
        var remaining = 1000 - len;
        if (remaining < 0) {
            remaining = 0;
        }
        $('.blogCommentCharacters').html(remaining + ' characters remaining');
        if (len >= 1000) {
            this.value = this.value.substring(0, 1000);
        }
    });
});

function MaxLength(text, long) {
    var maxlength = new Number(long);
    if (text.value.length > maxlength) {
        text.value = text.value.substring(0, maxlength);
    }
}

// DIRECTIONS CALLOUT 
$(document).ready(function() {
    var urlOriginal = "/Locations-and-Hours/Driving-Directions?form=driving_directions&includeATW=on";
    var address1;
    var address2;
    var urlBuilt;
	
    $(".locationCallout #directions_button").click(function() {
        address1 = $("#startaddress").val();
        address2 = $("#endaddress").val();
        urlBuilt = urlOriginal + "&address1=" + address1 + "&address2=" + address2;
        window.location = urlBuilt;
    });
	
	// Enter pressed...
	$('#startaddress').bind('keypress', function(e) {
        if(e.keyCode==13){		
			e.preventDefault();
			$(".locationCallout #directions_button").click();
        }
	});	
	
	// Enter pressed...
	$('#endaddress').bind('keypress', function(e) {
        if(e.keyCode==13){		
			e.preventDefault();
			$(".locationCallout #directions_button").click();
        }
	});
});
//END DIRECTIONS CALLOUT


//LOCATIONS CALLOUT
$(document).ready(function(){
	var urlOriginal = "/locations-and-hours/closest-cracker-barrel?form=locator_search&";
	var urlBuilt;
	var locationAddress;
	
	$(".locationCallout #locations_button").click(function(){
		locationAddress = $("#inputaddress").val();
		urlBuilt = urlOriginal + "locationAddress=" + locationAddress;
		window.location = urlBuilt;
	});
	
	// Enter pressed...
	$('#inputaddress').bind('keypress', function(e) {
        if(e.keyCode==13){		
			e.preventDefault();
			$(".locationCallout #locations_button").click();
        }
	});
});


//END LOCATIONS CALLOUT

//IFRAME PAGE DIRECTIONS / LOCATIONS
var urlOriginal;
var address1;
var address2;
var formType;
var locationLookup;
var urlBuilt;
var iframe;
var pageName;

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$(document).ready(function() {
	pageName = window.location.pathname;
	formType = getUrlVars()["form"];
	if(formType == "driving_directions"){
		address1 = getUrlVars()["address1"];
		address2 = getUrlVars()["address2"];
		//Load IFRAME with Above Content as data
		iframe = "<iframe class='locatorFrame' allowtransparency='true' frameBorder='0' scrolling='no' width='775px' height='485px' src='http://hosted.where2getit.com/crackerbarrel/locator-new.html?form=driving_directions&includeATW=on&addressline=" + address1 + "&addressline=" + address2 + "&driving_directions=Find+Locations'></iframe>";
		$("#directionsIframeContainer").html(iframe);
	} 
	else if(formType == "locator_search"){
		locationLookup = getUrlVars()["locationAddress"];
		
		iframe = "<iframe class='locatorFrame' allowtransparency='true' frameBorder='0' scrolling='no' width='775px' height='485px' src='http://hosted.where2getit.com/crackerbarrel/locator-new.html?form=locator_search&addressline=" + locationLookup +"'></iframe>";
		$("#directionsIframeContainer").html(iframe);
	} 
	//If loading directions page without passing data
	else {
		if(pageName == "/locations-and-hours/closest-cracker-barrel/"){
			iframe = "<iframe class='locatorFrame' allowtransparency='true' frameBorder='0' scrolling='no' width='775px' height='485px' src='http://hosted.where2getit.com/crackerbarrel/locator-new.html'></iframe>";
			$("#directionsIframeContainer").html(iframe);
		} 
		else if(pageName == "/locations-and-hours/driving-directions/"){
			iframe = "<iframe class='locatorFrame' allowtransparency='true' frameBorder='0' scrolling='no' width='775px' height='485px' src='http://hosted.where2getit.com/crackerbarrel/atw.html'></iframe>";
			$("#directionsIframeContainer").html(iframe);
		}
	}
});
//END IFRAME PAGE DIRECTIONS / LOCATIONS

// FOOTER LOCATION SEARCH
$(document).ready(function(){
	var locationsUrl = "/locations-and-hours/closest-cracker-barrel?form=locator_search&";
	var footerLocation;
	var e;
	
	$("#find-us .submit").click(function(){
		footerLocation = $("#find-us .text-field").val();
		urlBuilt = locationsUrl + "locationAddress=" + footerLocation;
		window.location = urlBuilt;
	});
	
	// Enter pressed...
	$('#find-us .text-field').bind('keypress', function(e) {
        if(e.keyCode==13){		
			e.preventDefault();
			$("#find-us .submit").click();
        }
	});		
});
//END FOOTER LOCATION SEARCH

// LEFT RAIL LOCATION SEARCH
$(document).ready(function(){
	var locationsUrl = "/locations-and-hours/closest-cracker-barrel?form=locator_search&";
	var footerLocation;
	
	$(".inputBoxes.leftRail .leftRailFinderSubmit").click(function(){
		footerLocation = $(".inputBoxes.leftRail .inputaddress").val();
		urlBuilt = locationsUrl + "locationAddress=" + footerLocation;
		window.location = urlBuilt;
	});
	
	// Enter pressed...
	$('.inputBoxes.leftRail .inputaddress').bind('keypress', function(e) {
        if(e.keyCode==13){		
			e.preventDefault();
			$(".inputBoxes.leftRail .leftRailFinderSubmit").click();
        }
	});
});
// END LEFT RAIL LOCATION SEARCH

// RESTAURANT IMAGE COLORBOX
$(document).ready(function() {
	$(".restaurant_img").click(function(){
		var sourceImg = $(this).attr('src');
		var splitSourceImg = sourceImg.split('?');
		var largeImg = '<img class="border restaurant_larg_img" alt="Larger Image" src="' + splitSourceImg[0] + '?w=640&h=342&as=1' + '" />';
		$('#restaurant_img-wrapper .shadow-four').html(largeImg);
		
		$(".restaurant_img").colorbox({
        inline: true,
        href: "#restaurant_img-wrapper",
        opacity: 0.5,
        overlayClose: false,
        scrolling: false,
        transition: 'none',
        onOpen: function() {
            $('#restaurant_img-wrapper').css('display', 'block');
        },
        onLoad: function() {
            $('#cboxClose').addClass('virtual-tour');
        },
        onCleanup: function() {
            $('#restaurant_img-wrapper').css('display', 'none');
        }
    });
	});
    // initialize colorbox
});
// END RESTAURANT IMAGE COLORBOX

// Add shadow code around any element with class="addShadow"
$(document).ready(function() {
    $('.addShadow').each(function() {
        $(this).after('<div class="clr">');
        $(this).wrap('<div class="shadow-one">');
        $(this).before('<div class="corner-a">');
        $(this).before('<div class="corner-b">');
        $(this).wrap('<div class="shadow-two">');
        $(this).wrap('<div class="shadow-three">');
        $(this).wrap('<div class="shadow-four">');
    });
});

// !!IMPORTANT!! TEMP FIX FOR CB BY MAIL
$(document).ready(function() {
	$('.leftnavMiddle a[href*="/place-your-order-online/"]').attr('href', 'http://ecrackerbarrel.com').attr('target', '_blank');
});
