var agt = navigator.userAgent.toLowerCase();
var browserid = agt.match(/(firefox|chrome|safari|opera|msie)/)[1];
var appVer = (agt.match(new RegExp('.+(?:version)[\/: ]([\\d.]+)')) || agt.match(new RegExp('.+(?:'+browserid+')[\/: ]([\\d.]+)')) || [0,'0'])[1];
var is_opera = (agt.indexOf("opera") != -1);
var is_chrome = (agt.indexOf("chrome") != -1);
var is_safari = (agt.indexOf("safari") != -1 && agt.indexOf("chrome") == -1);
var is_ie = (agt.indexOf('msie') != -1);
var is_firefox = (agt.indexOf('firefox') != -1);
var is_ie6 = (agt.indexOf('msie 6') != -1);


Cufon('.kozuka', {
   fontFamily: 'Kozuka Gothic Pr6N AJ16 OpenType',
   fontStretch: '99%'
   //textShadow: '#242728 1px 1px'
});

Cufon('.kozuka_action', {
   fontFamily: 'Kozuka Gothic Pr6N AJ16 OpenType',
   textShadow: '#05a185 4px 4px'
});

//textShadow: '#fff -1px -1px, #333 1px 1px

$(document).ready(function() {

    $('input[name=answer_type]').change(function() {
        var val = $(this).val();
        $('div[class^=answerdiv]').hide();
        $('div[class=answerdiv__'+val+']').show();
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',slideshow:4000});

	$('a[href=#]').attr('href', 'javascript:;');
	
	$('.valuelabel').valueLabel();
	
	$('a[rel=submit]').formSubmit();

    setInterval("changeMainImage();", 5000);


});

function changeMainImage() {
    var current = $('.main_images img:visible');
    var next = current.next();
    if(!next.length)
        next = $('.main_images img:first');
    current.fadeOut(1000);
    next.fadeIn(1000);
}

$.fn.valueLabel = function() {
	$(this).each(function() {
    	$(this).attr('fvalue', $(this).val());
		$(this).focus(function() {
			if($(this).val() == $(this).attr('fvalue') || $(this).val() == "")
				$(this).val('');
		}).blur(function() {
			if($(this).val() == $(this).attr('fvalue') || $(this).val() == "")
				$(this).val($(this).attr('fvalue'));
		});
	});
};

$.fn.formSubmit = function() {
	$(this).each(function() {
		$('<input type="submit" name="submit" value="submit" />').css('display', 'none').insertAfter($(this));
		$(this).click(function() {
			$(this).next().click();
			return false;
		});
	});
};

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
