// this can be made betterm but i dont know how :-s
var megadropdownisopen = true;

(function ($) {
	$(document).ready(function(){

		// .frontcontent .button pilen sættes ind
		$('.frontcontent .button').append('<span class="arrow"></span>');

		// frontpage news cycle
		if ($(".front #content .front-feature").length > 0) {

			$(".front #content .frontcontent .frontcycle").hide();
			$(".front #content .frontcontent .frontcycle:first").addClass("first").show();

			var size = $(".front #content .frontcontent").children().size()
			if (size > 1) {
				// init
				$(".front #content .front-feature").append("<div class='control'></div>");
				for (i = 0; i < size; i++) {
					var pager_class = (i == 0) ? 'active' : '';
					$(".front #content .front-feature .control").append('<a href="javascript:;" class="'+pager_class+'"></a>');
				}
				$(".front #content .front-feature .control a").bind("click", function() {
					var index = $(this).index();
					$(".front #content .front-feature .control a").removeClass("active");
					$(this).addClass("active");
					$(".front #content .frontcontent .frontcycle").hide();
					$(".front #content .frontcontent .frontcycle:eq("+index+")").show();

					$(".front #content .frontcontent").children().stop();
					cycle($(".front #content .frontcontent"), $(".front #content .front-feature .control"));
				});

				cycle($(".front #content .frontcontent"), $(".front #content .front-feature .control"));

			}
		}

	$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').hide();
	$('#block-views-mega-drop-down-block div.title').append('<div class="shadowfixer"></div>');
	$('#block-views-mega-drop-down-block .view-content .views-row div.title').mouseenter(function(){
		$('#block-views-mega-drop-down-block .view-content .views-row div.title').removeClass('active')
		$(this).addClass('active');
		$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').hide();
		$(this).siblings('.megadrop').show();
		return false;
	});

	$('#block-views-mega-drop-down-block .view-content .views-row div.title').hover(function() {megadropdownisopen=true});
	$('#block-views-mega-drop-down-block .view-content .views-row div.title').mouseover(function() {megadropdownisopen=true});
	$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').hover(function() {megadropdownisopen=true});
	$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').mouseover(function() {megadropdownisopen=true});


	$('#block-views-mega-drop-down-block .view-content .views-row div.title').mouseout(function() {megadropdownisopen=false});
	$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').mouseout(function() {megadropdownisopen=false});

	window.setInterval(function() {if (megadropdownisopen== false) {
		$('#block-views-mega-drop-down-block .view-content .views-row div.title').removeClass('active')
		$('#block-views-mega-drop-down-block .view-content .views-row .megadrop').hide();}
	}, 200);

	$('#block-views-mega-drop-down-block .megadrop .collums ul li').wrapInner('<span />');

	$('<span></span>').appendTo('#nav-secondary .menu-level-2 li a');

	}); // documnet ready end

	function cycle(parent, control) {
		parent.stop(); // does this do anything?
		var item = parent.find(":visible:first");
		var item_index = item.index();
		var new_index;
		item.fadeTo(6000, 1, function() {
			if (item_index == (parent.children().size()-1)) {
				item.fadeOut("normal");
				parent.find(":first").fadeIn("normal", function() {
					control.find("a").removeClass("active");
					control.find("a:first").addClass("active");
					cycle(parent, control);
				});
			}
			else {
			item.fadeOut("normal");
			item.next().fadeIn("normal", function() {
				new_index = parent.find(":visible:first").index();
				control.find("a").removeClass("active");
				control.find(":eq("+new_index+")").addClass("active");
				cycle(parent, control);
			});
			}
		});
	}

})(jQuery);;
/*jslint white: true, indent: 2, onevar: false, browser: true, undef: true, nomen: false, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, strict: false, newcap: true, immed: true */
/*global window, console, jQuery, setTimeout */

/*
  [INSERT_PLUGIN_NAME]
  [INSERT_VERSION_NUMBER]  
  Author and Contributors
  ========================================
  [INSERT_AUTHOR_LIST]
  
  File: jquery.iframe-auto-height.plugin.js  
  Remarks: original code from http://sonspring.com/journal/jquery-iframe-sizing      
  [INSERT_DESCRIPTION]
*/
(function ($) {
  $.fn.iframeAutoHeight = function (spec) {
    
    // set default option values
    var options = $.extend({
        heightOffset: 0, 
        minHeight: 0, 
        callback: function (newHeight) {},
        debug: false,
        diagnostics: false // used for development only
      }, spec);
    
    // logging
    function debug(message) {
      if (options.debug && options.debug === true && window.console) {
        console.log(message);
      }
    }    

    // not used by production code
    function showDiagnostics(iframe, calledFrom) {
      debug("Diagnostics from '" + calledFrom + "'");      
      try {
        debug("  " + $(iframe, window.top.document).contents().find('body')[0].scrollHeight + " for ...find('body')[0].scrollHeight");                  
        debug("  " + $(iframe.contentWindow.document).height() + " for ...contentWindow.document).height()");
        debug("  " + $(iframe.contentWindow.document.body).height() + " for ...contentWindow.document.body).height()");        
      } catch (ex) {
        // ie fails when called during for each, ok later on
        // probably not an issue if called in a document ready block         
        debug("  unable to check in this state");
      }
      debug("End diagnostics -> results vary by browser and when diagnostics are requested");
    }
    
    // show all option values
    debug(options);    

    // ******************************************************
    // iterate over the matched elements passed to the plugin
    $(this).each(function () {
      // for use by webkit only
      var loadCounter = 0;
            
      // resizeHeight
      function resizeHeight(iframe) {
        if (options.diagnostics) {
          showDiagnostics(iframe, "resizeHeight");
        }     
     
        // get the iframe body height and set inline style to that plus a little
        var $body = $(iframe, window.top.document).contents().find('body');
        var newHeight = $body[0].scrollHeight + options.heightOffset;
        
        if (newHeight < options.minHeight) {          
          debug("new height is less than minHeight");
          newHeight = options.minHeight + options.heightOffset;
        }

        debug("New Height: " + newHeight);
        iframe.style.height = newHeight + 'px';
        options.callback({newFrameHeight: newHeight});
      }
      
      // debug me
      debug(this);    
      if (options.diagnostics) {
        showDiagnostics(this, "each iframe");
      }      
      
      // Check if browser is Opera or Safari (Webkit really, so includes Chrome)
      if ($.browser.safari || $.browser.opera) {
        debug("browser is webkit or opera");
        
        // Start timer when loaded.
        $(this).load(function () {
          var delay = 0;
          var iframe = this;  
          // Reset iframe height to 0 to force new frame size to fit window properly          
          iframe.style.height = '0px';                     
          var delayedResize = function () {
            resizeHeight(iframe);
          };
          
          if (loadCounter === 0) {
            delay = 500; // delay the first one
          }
          
          debug("load delay: " + delay);
          setTimeout(delayedResize, delay);
          loadCounter++;          
        });

        // Safari and Opera need a kick-start.
        var source = $(this).attr('src');
        $(this).attr('src', '');
        $(this).attr('src', source);
      } else {
        // For other browsers.
        $(this).load(function () {
          resizeHeight(this);
        });
      } // if browser
             
    }); // $(this).each(function () {    
  }; // $.fn.iframeAutoHeight = function (options) {
}(jQuery)); // (function ($) {
;

