var cookiename = 'activelocation';
var activelocation;

function change(href)
{
	window.location.href = href;
}

function getBaseURL() {

    return 'http://www.thehickorytavern.com/';
    //return 'http://www.thehickorytavern.com/';

    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}

//$.noConflict();

var dialog;
var modal = $('a[rel="modal"]');



function openDialog(event, element, w, h) {

    event.preventDefault();

    var href = $(element).attr('href');
    var title = $(element).attr('title');
    var w=300;
    var h=200;

    $(dialog)
    .dialog('option', 'title', title)
    //.dialog( "option", "buttons", { 'Submit': function() { var id = $(this).attr('id'); $('#'+id+' > form').eq(1).submit(); } } )
    .dialog( "option", "buttons", { 'Submit': function() { $('#submit').trigger('click'); }, 'Cancel': function() { $(this).dialog('close'); } } )
    .load(href).dialog('open');


}

function submitForm(element){

  $(element).submit();

  //$(this).dialog('close');
}


function closeDialog(){
  $(this).dialog('close');
}


$(document).ready(function(){
    // events page

  	$(function() {
  		dialog = $("#dialog-modal").dialog({
  		  maxWidth: 600
  		  ,maxHeight: 400
  			,modal: true
        ,autoOpen: false
  		});
  	});

    var activelocation = $.cookie(cookiename);
    if(activelocation < 1) {
      var activelocation = $.cookie(cookiename, 1549);
    }



    // events page
    $(".location_dropdown").change(function () {
        var value = $(this).val();
        if(value){

            //window.location = '/events/'+value;
            $.cookie(cookiename, null);
            $.cookie(cookiename, value);
            //alert(value);
            //alert($.cookie(cookiename));
            //window.location.reload();
            window.location = getBaseURL()+'events';
        }
    })


    if($.cookie(cookiename)) {
      activelocation = $.cookie(cookiename);
      $(".location_dropdown option[value='"+activelocation+"']").attr('selected', 'selected');
    }


     // menu download
    $("#menu_download_dropdown").change(function () {
        var value = $(this).val();
        if(value){
            window.location = value;
        }
    })

    $('#flash_header').flash(
        { src: getBaseURL()+'resources/flash/logo_4/deploy/htavern_logo.swf',
          width: 300,
          wmode: 'transparent',
          height: 180 },
        { version: 8 }
    );


     // menu download
    $("#menu_download_dropdown").change(function () {
        var value = $(this).val();
        if(value){
            window.location = value;
        }
    })

    $('#slide_show').flash(
        { src: getBaseURL()+'resources/flash/photorow/deploy/home_photos.swf',
          width: 962,
          wmode: 'transparent',
          height: 260 },
        { version: 8 }
    );


    // header banner
     $('#banner_header').cycle({
		fx: 'fade'
	});

    // newsletter sign up
    var tog = false; // or true if they are checked on load
    $('#charlotte').click(function() {
        $(".checkbox-hopper input[type=checkbox]").attr("checked",!tog);
        tog = !tog;
    });

    // proshop page
    	simpleCart.email = "info@bitfliptech.com";
	simpleCart.checkoutTo = PayPal;
	simpleCart.currency = USD;
	simpleCart.taxRate  = 0.08;
//	simpleCart.shippingFlatRate = $.2$;
	simpleCart.shippingQuantityRate = 1.00;
/*	CartItem.prototype.shipping = function(){
		if( this.size ){
			switch( this.size.toLowerCase() ){
				case 'small':
					return this.quantity * 10.00;
				case 'medium':
					return this.quantity * 12.00;
				case 'large':
					return this.quantity * 15.00;
				case 'bull':
					return 45.00;
				default:
					return this.quantity * 5.00;
			}
		}
	};
*/

	simpleCart.cartHeaders = ["Thumb_image_noHeader", "Name" ,  "Quantity_input", "increment", "decrement","Total" , "Color_input_div_div","remove_noHeader" ];
});

$(document).ready(function(){


      var label = $('.location_dropdown option:selected', this).text();
      $(".location_area_text").html(label);
});
