jQuery.noConflict();
jQuery(document).ready(function($) {
// smooth-scroll to specified id automaticaly except #userarea
	$( 'a[href^="#"]:not(.notscroll)' ).not( '#userarea a' ).click( function() {
		if( $( this ).attr( 'href' ) != '#' ) {
			var youWillBeJumpTo = $( this ).attr( 'href' );
			var targetOffset = $( youWillBeJumpTo ).offset().top;
			var nowOffset = $( window ).scrollTop();
			var speed = Math.floor( Math.max( nowOffset,targetOffset ) - Math.min( nowOffset,targetOffset ) )/2;
			$( navigator.appName.match( /Opera/ ) ? 'html' : 'html,body' ).animate( {scrollTop:targetOffset}, speed );
		}

		return false;
	});

// CookiePlugin
	jQuery.cookie = function(name, value, options) {
	    if (typeof value != 'undefined') { // name and value given, set cookie
	        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(); // use expires attribute, max-age is not supported by IE
	        }
	        // CAUTION: Needed to parenthesize options.path and options.domain
	        // in the following expressions, otherwise they evaluate to undefined
	        // in the packed version for some reason...
	        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 { // only name given, get cookie
	        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]);
	                // Does this cookie string begin with the name we want?
	                if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;
	    }
	};


// search toggle switch 
	$( '#searchUpper em.openSwitch' ).click(function(){
		$( '#searchClose' ).slideUp('fast',function(){
			$( '#searchOpen' ).slideDown('fast');
			$( 'em.openSwitch' ).toggle();
			$( 'em.closeSwitch' ).toggle();
			$.cookie("mrSearch", '1',{expires: '',path: '/',domain: '.gnavi.co.jp'});
		});
	});
	$( '#searchUpper em.closeSwitch' ).click(function(){
		$( '#searchOpen' ).slideUp('fast',function(){
			$( '#searchClose' ).slideDown('fast');
			$( 'em.openSwitch' ).toggle();
			$( 'em.closeSwitch' ).toggle();
			$.cookie("mrSearch", '1',{expires: -1 ,path: '/',domain: '.gnavi.co.jp'});
			});
	});

// cookie Open
	if ($.cookie("mrSearch")){
		$( '#searchOpen' ).slideDown();
		$( 'em.openSwitch' ).hide();
		$( 'em.closeSwitch' ).show();
		} else {	
		$( '#searchOpen' ).hide();
		$( 'em.openSwitch' ).show();
		$( 'em.closeSwitch' ).hide();
		}


// menu candidate top
	var zind = 100;
	$( '.searchCuisineBlock > dd > .cuisineDetailMore, .searchPriceBlock > dd > .priceDetailMore' ).click( function(){
		var o = $( this );
		o.closest( 'div' ).find( 'div' ).hide();
		o.next().show();
		o.closest( 'dl' ).css('z-index',zind++);
	});
	
	$( '#cuisineAndPrice > dl > dd > div > a[class*="Close"]' ).click( function(){
		$( this ).parent().hide();
	});
	


// menu candidate search
	$( '#searchUpper ol > li > a.detailMore , #searchUnder ol > li > a.detailMore' ).click( function(){
		var o = $( this );
		$( '.areaDetailShowall,.cuisineDetailShowall,.priceDetailShowall' ).hide();
		o.closest( 'ol' ).next().show();
		o.closest( 'dl' ).css('z-index',zind++);
/*		o.next().show();*/
	});
	$( '#searchUpper dl > dd > div > a[class*="Close"] , #searchUnder > dl > dd > div > a[class*="Close"]' ).click( function(){
		$( this ).parent().hide();
	});
	



// products photos
	var celeb = {
		now: null,
		nowpos: -249,
		amount: 249,
		cp: $( '#products > .pickup > ul' ),
		ismoving: false,
		spd: 260
	}
	var int = new Number();
	int = setInterval( clickTriggerCeleb, 5 * 1000 );
	function clickTriggerCeleb() {
		$( '#productsControle .productsPageNumber .next a' ).trigger( 'click' );
	}
	$( ' > li:last', celeb.cp ).prependTo( celeb.cp );
	$( celeb.cp ).css( 'left', '-' + celeb.amount + 'px' );
	$( '#productsControle .productsPageNumber .prev a' ).click( function(){
		if( celeb.ismoving == false ) {
			celeb.ismoving = true;
			celeb.cp.animate( {left: ( celeb.nowpos + celeb.amount ) + 'px'}, celeb.spd ,function(){
				$( ' > li:last', celeb.cp ).prependTo( celeb.cp );
				$( celeb.cp ).css( 'left', '-' + celeb.amount + 'px' );
				celeb.ismoving = false;
			});
		}
		return false;
	});
	$( '#productsControle .productsPageNumber .next a' ).click( function(){
		if( celeb.ismoving == false ) {
			celeb.ismoving = true;
			celeb.cp.animate( {left: ( celeb.nowpos - celeb.amount ) + 'px'}, celeb.spd ,function(){
				$( ' > li:first', celeb.cp ).appendTo( celeb.cp );
				$( celeb.cp ).css( 'left', '-' + celeb.amount + 'px' );
				celeb.ismoving = false;
			});
		}
		return false;
	});

// new arrival photos
	var newarrival = {
		now: 0,
		nowpos: -683,
		amount: 683,
		cp: $( '#userPhoto > #userPhotoSlide > #slideContainer' ),
		ismoving: false,
		spd: 512,
		isover: false,
		amax: ( $( '#slideContainer > div.page').length - 1 ) * -1,
		amin: 0
	}
//	alert(newarrival.amax)
	var int = new Number();
	int = setInterval( clickTriggerPhoto, 5 * 1000 );
	function clickTriggerPhoto() {
		$( '.controller .controllerNext a' ).trigger( 'click' );
	}
	$( '.controller .controllerPrev a' ).click( function(){
			if( newarrival.ismoving == false ) {
				newarrival.ismoving = true;
				newarrival.now = ( newarrival.now != newarrival.amin ) ? newarrival.now + 1 : newarrival.amax;//-3;
				newarrival.cp.animate( {left: ( (newarrival.now) * newarrival.amount ) + 'px'}, newarrival.spd ,function(){
					newarrival.ismoving = false;
					var o = $( '#userPhoto > .controller > ul' );
					o.find( ' > .now' ).removeClass( 'now' );
					var p = ((newarrival.now * -1) + 1);
					o.find( 'a:contains("' + p + '")' ).parent().addClass( 'now' );
				});
			}
		return false;
	});
	$( '.controller .controllerNext a' ).click( function(){
			if( newarrival.ismoving == false ) {
				newarrival.ismoving = true;
				newarrival.now = ( newarrival.now != newarrival.amax ) ? newarrival.now - 1 : newarrival.amin;
				newarrival.cp.animate( {left: ( (newarrival.now) *  newarrival.amount ) + 'px'}, newarrival.spd ,function(){
					newarrival.ismoving = false;
					var o = $( '#userPhoto > .controller > ul' );
					o.find( ' > .now' ).removeClass( 'now' );
					var p = ((newarrival.now * -1) + 1);
					o.find( 'a:contains("' + p + '")' ).parent().addClass( 'now' );
				});
			}
		return false;
	});
	$( "#userPhoto > .controller > ul > li > a" ).click( function(){
			var o = $( this );
			if(!o.parent().hasClass( 'controllerNext' ) && !o.parent().hasClass( 'controllerPrev' )) {
				if( newarrival.ismoving == false ) {
					var yournum = -1 * (Number( o.html() ) - 1);
					if(newarrival.now != yournum ) {
						newarrival.ismoving = true;
						o.closest( 'ul' ).find( '.now' ).removeClass( 'now' );
						o.parent().addClass( 'now' );
						newarrival.cp.animate( {left: ( yournum * newarrival.amount ) + 'px'}, newarrival.spd ,function(){
							newarrival.ismoving = false;
						});
						newarrival.now = yournum;
					}
				}
			}
		return false;
	});

	// colorbox
		var opt = {
		width: '680px',
		height: '650px',
		iframe: true
	}
	$( '.cboxElement' ).each(function(){
		$( this ).colorbox( opt );
	});



})


