(function ($) {
    $.fn.heightAdjust = function (row, child) {
        this.each(function () {
            var elems = $(child, this);
            var nelems = elems.length;
            var heights = new Array(nelems);
            var setHeight = function () {
                for (var i = 0; i < nelems; i++) {
                    elems[i].style.height = "";
                    heights[i] = $(elems[i]).height();
                }
                var max = 0;
                for (var i = 0; i < nelems; i++) {
                    if (0 == i % row) {
                        max = Math.max.apply(Math, heights.slice(i, i + row));
                    }
                    heights[i] = max;
                }
                for (var i = 0; i < nelems; i++) {
                    elems[i].style.height = heights[i] + "px";
                }
            }
            setHeight();
            if ($("#font-checker").length == 0) {
                $("body").append('<div id="font-checker" style="position:absolute;left:-9999px;top:0;">&nbsp;</div>');
            }
            var baseSize = $("#font-checker").height();
            var checkSize = 0;
            setInterval(function () {
                checkSize = $("#font-checker").height();
                if (baseSize !== checkSize) {
                    setHeight();
                    baseSize = checkSize;
                }
            }, 1000);
        });

    }
})(jQuery);

(function ($) {
    $.fn.rollover = function () {
        var elems = this;
        var nelems = elems.length;
        var off = "_off";
        var on = "_on";
        var preLoadImg = new Object();
        for (var i = 0; i < nelems; i++) {
            preLoadImg[elems[i]] = new Image();
            preLoadImg[elems[i]].src = elems[i].src.replace(off, on);
            elems[i].onmouseover = function () {
                this.src = this.src.replace(off, on);
            }
            elems[i].onmouseout = function () {
                this.src = this.src.replace(on, off);
            }
        }
    }
})(jQuery);

$.event.add(window, "load", function(){
	var petalBoxShow = function(){
		if($.cookie('petalStart')){
			if(!$.cookie('petalOpen') || $.cookie('petalOpen') != 1){
				$('#petalbox').show().animate({right: 0}, 800);
			} else {
				$('#petalopen').show().animate({right: 0}, 800);
			}
		
			$(".petalbox-06", "#petalbox").click(function(){
				$('#petalbox').animate({right: -105}, 800, function(){
					$(this).hide();
					$.cookie('petalOpen', "1", {expires: 7, path: "/"});
					$('#petalopen').show().animate({right: 0}, 800);
				});
			});

			$('#petalopen').click(function(){
				$(this).animate({right: -105}, 1000, function(){
					$(this).hide();
					$.cookie('petalOpen', "0", {expires: 7, path: "/"});
					$('#petalbox').show().animate({right: 0}, 800);
				});
			});
		}
	}
	petalBoxShow();
	$("#petal-start").click(function(){
		petalBoxShow();
	});
});

$(function(){
    $("li.row-first", "ul.link-area").prev("li").addClass("row-last");
    $("img[src *= '_off.'], input[type = image]").rollover();
	$("#petal-start").click(function(){
		(!$.cookie('petalStart')) ? $.cookie('petalStart', "1", {expires: 7, path: "/"}) : '';
	});

	(!$.cookie("petal-01") && $.cookie("petalStart")) ? ($("#petal-01").show()) : '';
	(!$.cookie("petal-02") && $.cookie("petalStart")) ? ($("#petal-02").show()) : '';
	(!$.cookie("petal-03") && $.cookie("petalStart")) ? ($("#petal-03").show()) : '';

	var petalCount = 0;
	var countInsert = function(){
		petalCount = Number($.cookie("petal-01")) + Number($.cookie("petal-02")) + Number($.cookie("petal-03"));
		$("#petal-count").text(petalCount);
	}
	countInsert();

	$(".petals a").click(function(){
		var petalId = $(this).parent(".petals").attr("id");
		if(!$.cookie(petalId)){
			$.cookie(petalId, "1", {expires: 7, path: "/"});
			countInsert();
			$(this).fadeOut();
		}
	});

	switch (petalCount){
		case 1:

		break;

		case 2:
			
		break;

		case 3:
			
		break;

		default:

		break;
	}

	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'fast', /* fast/slow/normal */
		slideshow: 5000, /* false OR interval time in ms */
		autoplay_slideshow: false, /* true/false */
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: false, /* Resize the photos bigger than viewport. true/false */
		default_width: 500,
		default_height: 344,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'housemate', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		horizontal_padding: 20, /* The padding on each side of the picture */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: false, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
		overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: false, /* Set to false if you open forms inside prettyPhoto */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){}, /* Called when prettyPhoto is closed */
		ie6_fallback: true,
		markup: '<div class="pp_pic_holder"> \
					<div class="pp_top"> \
						<div class="ppt">&nbsp;</div> \
						<a class="pp_close" href="#">Close</a> \
						<div class="pp_left"></div> \
						<div class="pp_middle"></div> \
						<div class="pp_right"></div> \
					</div> \
					<div class="pp_content_container"> \
						<div class="pp_left"> \
						<div class="pp_right"> \
							<div class="pp_content"> \
								<div class="pp_loaderIcon"></div> \
								<div class="pp_fade"> \
									<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
									<div class="pp_hoverContainer"> \
										<a class="pp_next" href="#">next</a> \
										<a class="pp_previous" href="#">previous</a> \
									</div> \
									<div id="pp_full_res"></div> \
									<div class="pp_details"> \
										{pp_social} \
									</div> \
								</div> \
							</div> \
						</div> \
						</div> \
					</div> \
					<div class="pp_bottom"> \
						<div class="pp_left"></div> \
						<div class="pp_middle"></div> \
						<div class="pp_right"></div> \
					</div> \
				</div> \
				<div class="pp_overlay"></div>',
		social_tools: false
	});
});

