function two_layer_multiselect(primary_id, primary_values, secondary_id, secondary_values) {
   $.each(primary_values, function(key, value) {
       $("#"+primary_id).append('<option value="'+key+'">'+value+'</option>');
   });
   $("#"+primary_id).change({'primary_values': primary_values, 'secondary_values': secondary_values}, function(e) {
       var option_value = $("option:selected", this).val();
       var option_secondary_options = e.data.secondary_values[option_value];
       $("#"+secondary_id).empty();
       if(option_secondary_options) {
           $.each(option_secondary_options, function(key, value) {
               $("#"+secondary_id).append('<option value="'+key+'">'+value+'</option>');
           });
           $("#"+secondary_id+" option:first").click();
       }
   });
   $("#"+primary_id).change(); // Fire initial event
}
/**** variables for Games NEW tab ******/
var gamesNewOptions = {'g1':'Xbox 360', 'g2':'Mobile Games', 'g3':'Games for Windows', 'g4':'Kinect Games', 'g5':'Platinum Hits', 'g6':'Xbox LIVE Arcade', 'g7':'Games on Demand'} 
var gamesNewSecondaryOptions = {}
gamesNewSecondaryOptions['g1'] = {'s1':'All', 's2':'Action & Adventure', 's3':'Card & Board', 's4':'Classics', 's5':'Educational', 's6':'Family', 's7':'Fighting', 's8':'Music', 's9':'Other', 's10':'Platformer', 's11':'Puzzle & Trivia', 's12':'Racing & Flying', 's13':'Role Playing', 's14':'Shooter', 's15':'Sports & Recreation', 's16':'Strategy & Simulation'}
gamesNewSecondaryOptions['g2'] = {'s1':'All', 's2':'Featured Games', 's3':'Must-have Games'} 
gamesNewSecondaryOptions['g3'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesNewSecondaryOptions['g4'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesNewSecondaryOptions['g5'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesNewSecondaryOptions['g6'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesNewSecondaryOptions['g7'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'}

/**** variables for Games UPCOMING tab ******/
var gamesUpcomingOptions = {'g1':'Xbox 360', 'g2':'Mobile Games', 'g3':'Games for Windows', 'g4':'Kinect Games', 'g5':'Platinum Hits', 'g6':'Xbox LIVE Arcade', 'g7':'Games on Demand'} 
var gamesUpcomingSecondaryOptions = {}
gamesUpcomingSecondaryOptions['g1'] = {'s1':'All', 's2':'Action & Adventure', 's3':'Card & Board', 's4':'Classics', 's5':'Educational', 's6':'Family', 's7':'Fighting', 's8':'Music', 's9':'Other', 's10':'Platformer', 's11':'Puzzle & Trivia', 's12':'Racing & Flying', 's13':'Role Playing', 's14':'Shooter', 's15':'Sports & Recreation', 's16':'Strategy & Simulation'}
gamesUpcomingSecondaryOptions['g2'] = {'s1':'All', 's2':'Featured Games', 's3':'Must-have Games'} 
gamesUpcomingSecondaryOptions['g3'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesUpcomingSecondaryOptions['g4'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesUpcomingSecondaryOptions['g5'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesUpcomingSecondaryOptions['g6'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesUpcomingSecondaryOptions['g7'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 

/**** variables for Games BROWSE tab ******/
var gamesBrowseOptions = {'g1':'Xbox 360', 'g2':'Mobile Games', 'g3':'Games for Windows', 'g4':'Kinect Games', 'g5':'Platinum Hits', 'g6':'Xbox LIVE Arcade', 'g7':'Games on Demand'} 
var gamesBrowseSecondaryOptions = {}
gamesBrowseSecondaryOptions['g1'] = {'s1':'All', 's2':'Action & Adventure', 's3':'Card & Board', 's4':'Classics', 's5':'Educational', 's6':'Family', 's7':'Fighting', 's8':'Music', 's9':'Other', 's10':'Platformer', 's11':'Puzzle & Trivia', 's12':'Racing & Flying', 's13':'Role Playing', 's14':'Shooter', 's15':'Sports & Recreation', 's16':'Strategy & Simulation'}
gamesBrowseSecondaryOptions['g2'] = {'s1':'All', 's2':'Featured Games', 's3':'Must-have Games'} 
gamesBrowseSecondaryOptions['g3'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesBrowseSecondaryOptions['g4'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesBrowseSecondaryOptions['g5'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesBrowseSecondaryOptions['g6'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 
gamesBrowseSecondaryOptions['g7'] = {'s1':'All', 's2':'Featured', 's3':'Top Downloads', 's4':'LIVE Enabled'} 


$(document).ready(function() {
	two_layer_multiselect("gamesNewSelect", gamesNewOptions, "gamesNewSecondarySelect", gamesNewSecondaryOptions);
	
	two_layer_multiselect("gamesUpcomingSelect", gamesUpcomingOptions, "gamesUpcomingSecondarySelect", gamesUpcomingSecondaryOptions);
	
	two_layer_multiselect("gamesBrowseSelect", gamesBrowseOptions, "gamesBrowseSecondarySelect", gamesBrowseSecondaryOptions);
});


//$(document).ready(function() {
/*	function addOption(selectbox,text,value ) {
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
	}
	
	function addOption_list(selectbox){
		var month = new Array("Fruits","Games","Scripts");
		for (var i=0; i < month.length;++i){

		addOption(document.drop_list.Category, month[i], month[i]);
		}
	}
	*/
	/*function fillCategory(){ 
	 // this function is used to fill the category list on load
	addOption(document.drop_list.Category, "Fruits", "Fruits", "");
	addOption(document.drop_list.Category, "Games", "Games", "");
	addOption(document.drop_list.Category, "Scripts", "Scripts", "");
	}*/

/*	function SelectSubCat(){
	// ON selection of category this function will work

	removeAllOptions(document.drop_list.SubCat);
	addOption(document.drop_list.SubCat, "", "SubCat", "");

	if(document.drop_list.Category.value == 'Fruits'){
	addOption(document.drop_list.SubCat,"Mango", "Mango");
	addOption(document.drop_list.SubCat,"Banana", "Banana");
	addOption(document.drop_list.SubCat,"Orange", "Orange");
	}
	if(document.drop_list.Category.value == 'Games'){
	addOption(document.drop_list.SubCat,"Cricket", "Cricket");
	addOption(document.drop_list.SubCat,"Football", "Football");
	addOption(document.drop_list.SubCat,"Polo", "Polo", "");
	}
	if(document.drop_list.Category.value == 'Scripts'){
	addOption(document.drop_list.SubCat,"PHP", "PHP");
	addOption(document.drop_list.SubCat,"ASP", "ASP");
	addOption(document.drop_list.SubCat,"Perl", "Perl");
	}

	}
	////////////////// 

	function removeAllOptions(selectbox)
	{
		var i;
		for(i=selectbox.options.length-1;i>=0;i--)
		{
			//selectbox.options.remove(i);
			selectbox.remove(i);
		}
	}


	function addOption(selectbox, value, text )
	{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;

		selectbox.options.add(optn);
	}*/
//});
