/*! Copyright (c) 2009 MasterCard Debit
 *
 * Version: 1.2
 * Date: 16 June 2009
 * 
 */
 
$(function()
{
	// the hover for navigation
	$("#navigation a").hover(
		function(){
			$(this).css('background-position', '0px -20px');
		},
		function(){
			$(this).css('background-position', '0px 0px');
		}
	);

	// the active state for navigation
	switch(pg_active)
	{
	case 'home':
	  var src = 'images/nav/nav_home.png';
	  break;
	case 'eventsandcomps':
	  var src = 'images/nav/nav_evcomp.png';
	  break;
	case 'photosandvideos':
	  var src = 'images/nav/nav_phvid.png';
	  break;
	case 'extras':
	  var src = 'images/nav/nav_extras.png';
	  break;
	  case 'debitinfo':
	  var src = 'images/nav/nav_debit.png';
	  break;
	case 'signup':
	  var src = 'images/nav/nav_signup.png';
	  break;
	default:
	  return;
	}

	$('.'+ pg_active).css('background-position', '0px -20px');
	$('.' + pg_active).unbind();
});



$(function()
{
	// the hover for all classes of type hovele (images must be of extension .gif)
	$(".hov_gif").hover(

		function(){
			if($(this).attr("src").indexOf("_on") == -1) {
			var newSrc = $(this).attr("src").replace("_off.gif","_on.gif");
			$(this).attr("src",newSrc);
			}
		},

		function(){
			if($(this).attr("src").indexOf("_on.gif") != -1) {
			var oldSrc = $(this).attr("src").replace("_on.gif","_off.gif");
			$(this).attr("src",oldSrc);
			}
		}
	);
});



function homeFeature(list)
{
	// the feature panel on the homepage
	$('#event_comps_intro').empty();

	$.ajax({
		type: "GET",
		url: base_url + "xml/eventsComps.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			count = 1; 
			for ( var i in list )
			{
				$(xmlData).find('label[id='+list[i]+']').each(function(){ 

					var id = $(this).attr('id'); 
					var type = $(this).find('type').text();
					var title = $(this).find('title').text();
					var date = $(this).find('date').text();
					var description = $(this).find('description').text();
					
					if(count == 1){ cs = "class = 'a bottom'";}
					if(count == 2){ cs = "class = 'b bottom'";}
					if(count == 3){ cs = "class = 'a'";}
					if(count == 4){ cs = "class = 'b'";}

					if(type == 'event'){ 
						var readmore_abbrv = 'Find out more&raquo;' 
						var link = 'events/'+id+'/';
					}
					if(type == 'comp'){ 
						var readmore_abbrv = 'Enter now&raquo;' 
						var link = 'competitions/'+id+'/';
					}
					// clean title value for HBX Link Tracking
					// ? ' " & ! # $ % ^ * : | / \ < > ~ ;
					var re = new RegExp ('[\?\'\"\&!#\$%^\*:\/\\<>~;]', 'g') ;
					var cleantitle = title.replace(re, '') ;

					$('<div '+cs+'>')
						.html("<a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='140' height='100' alt='"+title+"'/></a>" +
							  "<h1><a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'>" +title+ "</a></h1><p>"+description+
							  " <span class='readmore'><a href='"+link+"' title='"+readmore_abbrv+"' name='&lid="+cleantitle+"&lpos="+type+"'>"+readmore_abbrv+"</a></span></p>")
						.appendTo('#event_comps_intro');		

					count ++;
				});
			}
		}
	});
}



function mediaFeedLimit(list)
{
	$('#sidebar_feed').empty();

	$.ajax({
		type: "GET",
		url: base_url + "xml/media.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			for ( var i in list )
			{
				$(xmlData).find('label[id='+list[i]+']').each(function(){ 

					var id = $(this).attr('id'); 
					var type = $(this).find('type').text();
					var title = $(this).find('title').text();
					var date = $(this).find('date').text();
					var description = $(this).find('description').text();

					// clean title value for HBX Link Tracking
					// ? ' " & ! # $ % ^ * : | / \ < > ~ ;
					var re = new RegExp ('[\?\'\"\&!#\$%^\*:\/\\<>~;]', 'g') ;
					var cleantitle = title.replace(re, '') ;
					
					if(type == 'photo'){
					
						var link = base_url+'media/photos/'+id+'/';

						$('<div class="row">')
							.html("<a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='96' height='96' align='left' alt='"+title+"'/></a>"+
								  "<h1><a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'>"+title+"</a></h1><p>"+
								  "<p>"+description+"</p>"+
								  "<div style='clear:both;'></div>")
							.appendTo('#sidebar_feed');		
					}

					if(type == 'video'){ 

						var link = base_url+'media/videos/'+id+'/';

						$('<div class="row">')
							.html("<a class='videoplayer' href='"+base_url+"media/videos/"+id+"/index.html' title='"+title+"' target='_blank' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='96' height='96' align='left' alt='"+title+"'/></a>"+
								  "<h1><a class='videoplayer' href='"+base_url+"media/videos/"+id+"/index.html' title='"+title+"' name='&lid="+cleantitle+"&lpos="+type+"' target='_blank'>"+title+"</a></h1><p>"+
								  "<p>"+description+"</p>"+
								  "<div style='clear:both;'></div>")
							.appendTo('#sidebar_feed');		
					}

					
					if(type == 'extra'){ 
					
						var link = base_url+'media/extras/'+id+'/';
						var dload = base_url+'media/extras/'+id+'/1280x1024.jpg';

						$('<div class="row">')
							.html("<a href='"+dload+"' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='96' height='96' align='left' alt='"+title+"'/></a>"+
								  "<h1><a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'>"+title+"</a></h1><p>"+
								  "<p>"+description+"</p>"+
								  "<div style='clear:both;'></div>")
							.appendTo('#sidebar_feed');		
					}

				});
			}
		}
	});
}	



function eventsCompsAll()
{
	$('#event_comps').empty();

	$.ajax({
		type: "GET",
		url: base_url + "xml/eventsComps.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			$(xmlData).find('label').each(function(){ 

				var id = $(this).attr('id'); 
				var type = $(this).find('type').text();
				var title = $(this).find('title').text();
				var date = $(this).find('date').text();
				var description = $(this).find('description').text();

				// clean title value for HBX Link Tracking
				// ? ' " & ! # $ % ^ * : | / \ < > ~ ;
				var re = new RegExp ('[\?\'\"\&!#\$%^\*:\/\\<>~;]', 'g') ;
				var cleantitle = title.replace(re, '') ;

				if(type == 'event'){ 
					var readmore_abbrv = 'Find out more&raquo;' 
					var link = 'events/'+id+'/';
				}

				if(type == 'comp'){ 
					var readmore_abbrv = 'Enter now&raquo;' 
					var link = 'competitions/'+id+'/';
				}

				$('<div class="row">')
						.html("<a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='140' height='100' alt='"+title+"'/></a>" +
						  "<h1><a href='"+link+"' name='&lid="+cleantitle+"&lpos="+type+"' >" +title+ "</a></h1><p>"+description+
						  " <span class='readmore'><a href='"+link+"' title='"+readmore_abbrv+"' name='&lid="+cleantitle+"&lpos="+type+"'>"+readmore_abbrv+"</a></span></p>")
					.appendTo('#event_comps');		
			}); 
		}
	});
}



function extrasAll(){

	$('#extras_page').empty();

	$.ajax({
		type: "GET",
		url: base_url + "xml/media.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			$(xmlData).find('label').each(function(){ 

				var id = $(this).attr('id'); 
				var type = $(this).find('type').text();

				if(type == 'extra'){

					var link = 'media/extras/'+id+'/';
					var title = $(this).find('title').text();
					var date = $(this).find('date').text();
					var description = $(this).find('description').text();
					var dload = base_url+'media/extras/'+id+'/1280x1024.jpg';
					
					// clean title value for HBX Link Tracking
					// ? ' " & ! # $ % ^ * : | / \ < > ~ ;
					var re = new RegExp ('[\?\'\"\&!#\$%^\*:\/\\<>~;]', 'g') ;
					var cleantitle = title.replace(re, '') ;

					$('<div class="row">')
						.html("<a href='"+dload+"' name='&lid="+cleantitle+"&lpos="+type+"'><img src='"+link+"thumb.jpg' width='96' height='96' alt='"+title+"' align='left'/></a>" +
							  "<h1><a href='"+dload+"' name='&lid="+cleantitle+"&lpos="+type+"'>" +title+ "</a></h1><p>" +description+ "</p>")
						.appendTo('#extras_page');	
				}
			});			
		}
	});
}