$(document).ready(function() {   
	effects_init();
});

$(function() {
	$('#photogal_box').cycle({
	    fx:     'scrollHorz',
	    easing: 'easeOutSine',
	    prev:   '#photo_prev',
	    next:   '#photo_next',
	    prevNextClick:	on_photo_change,
	    nowrap:  1,
	    timeout: 0
	});
})

function on_photo_change(isNext, zeroBasedSlideIndex, slideElement, elementsCount) {
	var $pre = $("a#photo_prev");
	var $next = $("a#photo_next");
	
	if(isNext) {
		if ($pre.is(":hidden")) {
			$pre.fadeIn("normal");
		}
		if (zeroBasedSlideIndex == elementsCount - 1) {
			$next.fadeOut("normal");
		}
	}
	else {
		if ($next.is(":hidden")) {
			$next.fadeIn("normal");
		}
		if (zeroBasedSlideIndex == 0) {
			$pre.fadeOut("normal");
		}
	}
}
	
function effects_init() {
	//$("div#main_box_inner").addClass("hidden");
 	setTimeout(content_effect, 300);

	$("div#main_menu div.l1 a").hoverIntent(menu_item_over, menu_item_out);

	$("div#main_menu div.sub_open a")
    .bind("click", function(){
    	var sub = $(this).parent().next();
		
    	if (sub.is(":hidden")) {
			sub.slideDown("fast");
		}
		else {
			sub.slideUp("fast");
		}    
    });
    
    $("div#foot a")
    .bind("mouseover", function(){
    	$(this).parent().children("span").slideDown("fast");
    })
    .bind("mouseout", function(){
    	$(this).parent().children("span").slideUp("fast");
    });
    
    $("div.img_wrap img").noContext();
    
    $("div.wysiwyg a span")
	.filter(function () {
		return $(this).attr("style").toLowerCase() == "color: #00a5f9" ? true : false;
	})
    .parent().addClass("blue");
}

function content_effect() {
    $("div#main_box_inner").slideDown(1000);
}

function menu_item_over() {
	$(this).parent().children("span").not(".over").animate({ width:"158px" }, "fast");
	
	if ($(this).hasClass("top_over")) {
	   	var target = $(this).attr("rel");
		$('div#head img.under_img' + target).fadeOut("normal");
	}
}

function menu_item_out() {
	$(this).parent().children("span").not(".over").animate({ width:"0" }, "fast");

	if ($(this).hasClass("top_over")) {
		var target = $(this).attr("rel");
		$('div#head img.under_img' + target).fadeIn("normal");
	}
}