function confirmAction(message, url) {
	if(confirm(message)) {
		document.location.href = url;
	}
}

function nl2br(str, is_xhtml) {

    var breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }

    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}

function applyButtonStyle() {
	
	$("input").filter("[type=submit]").add("[type=button]").each(function(i){
		if($(this).parent('div').hasClass('inputWrapper') == false) {
			$(this).addClass('button');

			$(this).hover(
				function() {
					$(this).css('color','silver');
				},
				function() {
					$(this).css('color','white');
				}
			);
		}
	});
}

// jquery
$(document).ready(function() {
	// flickering animation class
	$(".animate").each(function(i) {
		
		var oldColor = $(this).css('color');
		
		$(this).css('color','red');
		
		$(".animate").animate({ opacity: 0.0 }, 300);
		$(".animate").animate({ opacity: 1.0 }, 600);
		$(".animate").animate({ opacity: 0.0 }, 300);
		$(".animate").animate({ opacity: 1.0 }, 600);
		$(".animate").animate({ opacity: 0.0 }, 300);
		$(".animate").animate({ opacity: 1.0 }, 600);
		$(".animate").animate({ opacity: 0.0 }, 300);
		$(".animate").animate({ opacity: 1.0 }, 600);
		$(".animate").animate({ opacity: 0.0 }, 300);
		$(".animate").animate({ opacity: 1.0 }, 600, function() { 
														$(this).css('color',oldColor); 
													 });
		
		
	});
	

	// png transparency
	$("img[src$=png]").pngfix();

	function loadMain() {
		$(".gallery .mainImage").fadeOut("slow", function() {

			// create loader image
			var _loader = new Image();

			$(_loader).load(function () {
				$(".gallery .mainImage").html('<img src="' + $(".active .thumb").attr('name') + '" border="0" />');
				$(".gallery .mainImage").fadeIn("slow");
			});

			$(_loader).attr('src', $(".active .thumb").attr('name'));
		});
	}

	// gallery
	$(".gallery ul li img").click(function() {

		$(".active").removeClass('active');
		$(this).parent("li").addClass('active');

		loadMain();
	});

	$(".gallery .mainImage").click(function() {
		if($(".active").next("li").parent("ul").parent('div').attr('class') == 'gallery') {
			var current = $(".active");
			var next = $(".active").next();

			current.removeClass('active');
			next.addClass('active');
		}
		else {
			$(".active").removeClass('active');
			$(".gallery ul li:first").addClass('active');
		}

		loadMain();
	});

	$(".gallery .mainImage").css('display','none');
	$(".gallery .mainImage").html('<img src="' + $(".gallery ul li img:first").attr('name') + '" galleryimg="no" border="0" />');
	$(".gallery .mainImage").fadeIn("slow");

	// input border = 1 exclude
	$("input[type='radio']").css('border','0px');

	//messagebox hide
	$(document).bind('keypress', function(e) {
    	$("#messageBox").css('display','none');
	});

	//Hover cylce row	
	$(".cycleRow").hover(
		function() {			
			$(this).addClass('activeRow');
		},
		function() {			
			$(this).removeClass('activeRow');
		}
	);

	
	// Rounded buttons
	applyButtonStyle();

});
