$(document).ready(function() {
	// links (GNB)
	$('h1').click(function() {window.location="/";});
	$('#menuItems #menu1').click(function() {window.location="/whatisbada/";});
	$('#menuItems #menu2').click(function() {window.location="/badadevices/";});
	$('#menuItems #menu3').click(function() { /*window.location="/developer/"; */ window.open('http://developer.bada.com','_blank');});
	$('#menuItems #menu4').click(function() {window.location="/category/blog/";});

	$('#searchBtn').click(function() {$('#searchform')[0].submit();});

	// links (GNB - Sub)
	$('#submenu0101').click(function() {window.location="/whatisbada/whatisbada";});
	$('#submenu0102').click(function() {window.location="/whatisbada/eventplans";});
	$('#submenu0103').click(function() {window.location="/whatisbada/artgallery";});
	$('#submenu0104').click(function() {window.location="/whatisbada/ecosystem";});

	$('#submenu0201').click(function() {window.location="/badadevices/";});
/*	$('#submenu0202').click(function() {window.location="/business/partner/";});
	$('#submenu0301').click(function() {window.location="/developer/";});
	$('#submenu0302').click(function() {window.location="/developer/challenge/";});
	$('#submenu0303').click(function() {window.location="/developer/day/";});
*/

	// links (footer)
	$('#footMenuTerms').click(function() {window.location="/terms/";});
	$('#footMenuContact').click(function() {window.location="mailto:contact.bada@samsung.com";});
	$('#footMenuSitemap').click(function() {window.location="/sitemap/";});
	$('#footMenuMoblie').click(function() {window.open("http://innovator.samsungmobile.com/index.do");});
	$('#footMenuAstore').click(function() {window.open("http://www.samsungapps.com/ ");});
	$('#footMenuDevelopers').click(function() {window.open("http://developer.bada.com/ ");});
	$('#footMenuMedia').click(function() {window.open("http://www.samsungbadamedia.com/ ");});
	$('#footMenuSH').click(function() {window.open("http://socialhub.samsungmobile.com/ ");});

	// 1Depth hover
	$('#menuItems li').hover(
		function() {var submenu = '#sub' + $(this).attr('id'); $(submenu).show(); delTimeout_('sub' + $(this).attr('id'));},
		function() {setTimeout_('sub' + $(this).attr('id'));}
	);

	// submenu hover (hole)
	$('#submenu1, #submenu2, #submenu3').hover(
		function() {$(this).show(); delTimeout_($(this).attr('id'));},
		function() {setTimeout_($(this).attr('id'));}
	);

	// footer hover
	$('#footMenu li').hover(
		function() {$(this).css('background-position','0 -16px');},
		function() {$(this).css('background-position','0 0');}
	);
	
	// footer hover2
	$('#copyright li').hover(
		function() {$(this).css('background-position','0 -16px');},
		function() {$(this).css('background-position','0 0');}
	);
	
	// footer hover2
	$('#RightLink li').hover(
		function() {$(this).css('background-position','0 -20px');},
		function() {$(this).css('background-position','0 0');}
	);

	searchOnBlur();

	/* ie6 fix */
	if ($.browser.msie && $.browser.version=="6.0") {
		// 1Depth hover
		$('#menuItems li div').hover(
			function() {$(this).css('background-position','0 -25px').css('height','25px').css('margin-top','12px');},
			function() {$(this).css('background-position','0 0px').css('height','24px').css('margin-top','13px');}
		);

		// submenu hover (2 depth)
		$('#submenu .bg div div').hover(
			function() {$(this).css('background-position','0 -31px');},
			function() {$(this).css('background-position','0 0');}
		);

		// btnVoice Hover
		$('#btnVoice').hover(
			function() {$(this).css('background-position','0 -39px');},
			function() {$(this).css('background-position','0 0')}
		);

		// Addthis
		$('#addthis_button').hover(
			function(event) {
				$('#at15s').css('top',event.pageY);
				$('#at15s').css('left',event.pageX - 110);
			}
		);
	} else {
		// 1Depth hover
		$('#menuItems li div').hover(
			function() {$(this).css('background-position','0 -27px');},
			function() {$(this).css('background-position','0 0px');}
		);

		// submenu hover (2 depth)
		$('#submenu .bg div div').hover(
			function() {$(this).css('background-position','0 -31px');},
			function() {$(this).css('background-position','0 0');}
		);

		// see meore hover
		$('.seeMore span').hover(
			function() {$(this).css('background-position','0px -10px');},
			function() {$(this).css('background-position','0px 0');}
		);

		DD_roundies.addRule('.tagcloud a', '3px', true);
	}

	// will move to contents
	$('.wallpaper').addClass("clearfix");
});

// searchbox
function searchOnBlur() {
	var value = $('#search').attr('value');
	if (!value) $('#search').addClass('blank');
}

function searchOnFocus() {
	$('#search').removeClass('blank');
}

function fold(elm) {
	if ($('#'+elm+'_btn').hasClass('open')) {
		$('#'+elm+'_btn').css('background-image','url(http://dpimg.ospos.net/marketing/images/icon_bullet.png)');
		$('#'+elm+'_months').hide();
		$('#'+elm+'_btn').removeClass('open');
	} else {
		$('#'+elm+'_btn').css('background-image','url(http://dpimg.ospos.net/marketing/images/icon_bullet_bottom.png)');
		$('#'+elm+'_months').show();
		$('#'+elm+'_btn').addClass('open');
	}
}

var timeout = new Array();

function setTimeout_(id) {
	timeout[id] = setTimeout('hideMenu("'+id+'")', 50);
}
function delTimeout_(id) {
	clearTimeout(timeout[id]);
}

function hideMenu(id) {
	$('#'+id).hide();
}

function showMenu(id) {
	$('#'+id).show();
}

// border - round
DD_roundies.addRule('.radius5', '5px', true);
