// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

jQuery.noConflict();

//List of controller specific js files
//themes_controller.js.

jQuery.ajaxSetup({
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});

jQuery(document).ready(function($) {
  $(".add_to_cart").live("click", function() {
      $.post($(this).parent().parent().attr("action"), $(this).serialize(), null, "script");
//      alert("clicked");
      return false;
  });
  $(".remove_from_cart").live("click", function() {
      $.post($(this).parent().parent().attr("action"), $(this).serialize(), null, "script");
//      alert("clicked");
      return false;
  });
  $(".empty_cart").live("click", function() {
      $.post($(this).parent().parent().attr("action"), $(this).serialize(), null, "script");
//      alert($(this).parent().parent().attr("action"));
      return false;
  });
  $(".use_ajax").live("click", function() {
      $.get(this.href, null, null, "script");
      return false;
  });
  $(".paginate").live("click", function() {
      $('.product-store').fadeOut('slow', function() {
//        $("#merchant-products").fadeOut("fast");
      });
      
      $.get(this.href, null, null, "script");
      return false;
  });
});
//jQuery(document).ready(function($){
//    $(function(){
//            $('#theme_layout').css({ width: $("#website_layout_website_width").val() + '%'});
//            $('#theme_fixed').css("padding-top", $("#website_layout_website_height").val() + '%');
//            $('#theme_fixed').css("padding-bottom", $("#website_layout_website_height").val() + '%');
//    });
//});


// This code initialises the website preview borders to the values of the input fields when the form loads up
//
//jQuery(document).ready(function($){

//        $('#theme_layout').css({ width: $("#website_layout_website_width").val() + '%'});
//        $('#theme_fixed').css("padding-top", $("#website_layout_website_height").val() + '%');
//        $('#theme_fixed').css("padding-bottom", $("#website_layout_website_height").val() + '%');
//    });
//});

//jQuery(document).ready(function($){
    //$(function(){
        //$("a.catalogue-menu").click(function (e) {
            //alert ("clicked");
//          $(this).children.toggle();//(this.children);// animate({ height: 'hide', opacity: 'hide' }, 'slow');
        //});
    //});
//});

//jQuery.fn.submitWithAjax = function() {
//  this.submit(function() {
//    $.post(this.action, $(this).serialize(), null, "script");
//    return false;
//  })
//  return this;
//};

//jQuery(document).ready(function() {
//  $(".add_to_cart").submitWithAjax();
//})

//This code changes the height and width of the border as you type
jQuery(document).ready(function($){
    $(function(){
        $("#website_layout_website_width").keyup(function (e) {
            $('#theme_layout').css({ width: $(this).val() + '%'});
        });
    });
});

jQuery(document).ready(function($){
    $(function(){
        $("#website_layout_website_height").keyup(function (e) {
           $('#theme_fixed').css( "padding-top", $(this).val() + '%');
           $('#theme_fixed').css( "padding-bottom", $(this).val() + '%');
        });
    });
});

//Rounded corners
jQuery(document).ready(function($){
    $(function(){
            $(".verticalmenu").corner();
            $("#header ul li a").corner("Top");
            $("#header").corner("Top 45px");
            $("#footer").corner("Bottom 45px");
            $("#store").corner("15px");
    });
});

jQuery(document).ready(function($){
  $('a.get').click(function() {
	  $("#store").animate({ height: 'hide', opacity: 'hide' }, 'fast');
//	  $("#store").animate({ height: 'show', opacity: 'show' }, 'slow');
  });
});

//jQuery(function($) {
//  $('a.get').click(function() {
//	  $("#store").animate({ height: 'hide', opacity: 'hide' }, 'slow');
//	  $("#store").animate({ height: 'show', opacity: 'show' }, 'slow');
//  });
//});
   
//jQuery( function($) { // $(document).ready() shorthand
//   $("#store").animate({ height: 'hide', opacity: 'hide' }, 1500)
//});
//jQuery(function($) {
//  ${mark_for_destroy(element){
//  alert('Removing')
//  jQuery(element).next('.should_destroy').value='1';
//  jQuery(element).hide('slow');
//};
function mark_for_destroy(element){
  alert('Removing ' + element);
}

function myFileBrowser (field_name, url, type, win) {
		cmsURL = "/admin/file_browser";
    tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'File Browser',
        width : 640,
        height : 480,
        resizable : "yes",
        inline : "yes",
        close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
    return false;
  }