//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
Function.prototype.forEach = function(object, block, context) {
  for (var key in object) {
    if (typeof this.prototype[key] == "undefined") {
      block.call(context, object[key], key, object);
    }
  }
};
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}
var forEach = function(object, block, context) {
	  if (object) {
	    var resolve = Object; // default
	    if (object instanceof Function) {
	      // functions have a "length" property
	      resolve = Function;
	    } else if (object.forEach instanceof Function) {
	      // the object implements a custom forEach method so use that
	      object.forEach(block, context);
	      return;
	    } else if (typeof object.length == "number") {
	      // the object is array-like
	      resolve = Array;
	    }
	    resolve.forEach(object, block, context);
	  }
	};


//jkmegamenu.definemenu("anchorid", "menuid", "mouseover|click")
jkmegamenu.definemenu("cities_anchor", "cities_menu", "mouseover");
jkmegamenu.definemenu("tools_anchor", "tools_menu", "mouseover");
if (typeof( categoriesEnabled ) !== 'undefined' && categoriesEnabled)
	jkmegamenu.definemenu("category_anchor", "categories_menu", "mouseover");
$(document).ready(function(){

	if ($('form#comment_form')[0]) {
		$('form#comment_form')[0].action='';
	}
	if ($('form#email_friend')[0]) {
		$('form#email_friend')[0].action='';
	}
    $('div#image_container a.button').button();
    $('a.image_button').click(function () {
    	$('#media-container').html('<img src="'+this.href+'" alt="" />');
    	return false;
    });


    if (typeof($('a.video_button')[0])!='undefined') {
    	$('a.video_button').click

    }

    $('a.video_button').click(function () {
    	$('#media-container').html('<div id="video-container"><img src="'+CURRENT_THEME_URL+'images/icons/ajax-loader.gif" class="ajax-loader"/></div>');
    	var params = { allowScriptAccess: "always", wmode: "transparent" };
        var atts = { id: "video-container", wmode: "transparent" };
        swfobject.embedSWF(this.href,
                           "video-container", "387", "290", "8", null, null, params, atts);
        return false;
    }).click();
    $('div.comment-pages a').button();
    $('a#show_comments').click(function () {
    	$('div.comments_list').slideToggle();
    	return false;
    });
});

function shareonfacebook(facebookmessage,facebooklink,facebooktitle,facebookdescription,imagesource) {
    FB.ui(
    {
        method: 'stream.publish',
        message: facebookmessage,
        attachment: {
            name: facebooktitle,
            description: (facebookdescription),
            href: facebooklink,
            media: [{ 'type': 'image', 'href': facebooklink, 'src': imagesource}]
        },
        action_links: [{ text: 'Code', href: facebooklink }],
        user_prompt_message: 'Share this deal'
    });
} 
