//RUN ON ALL PAGES
//===========================================//
function getURL(loc){ window.location = loc;}

jQuery(function(){
    jQuery('.newsletter').show();
	jQuery('.newsletter').click(function(){
		$.panther.jcall('servUp', ["/_tpl/nl_form", ".nl_form"]);
		jQuery(".nl_form").placer(".newsletter",{offsetX:-258,offsetY:-235}).fadeIn();
		return false;
	});

});
//===========================================//
jQuery.centro={};

//SHOWCASE
jQuery.centro.creativeSort = function(){
  jQuery("#creative_sort").change(function(){
	if(jQuery(this).val() > 2) {
		// create new select if it doesn't exist
		if(jQuery('#creative_type').length === 0){
			jQuery(".x_menLoader").fadeIn('slow');
			jQuery('<select id="creative_type"></select>').hide().insertAfter('#creative_sort');
			jQuery("#creative_type").change(function(){
				getURL('/media-services/showcase/sort/' + jQuery(this).val());
			});
		}
		getCategoryNames(this);

		} else {
			if (jQuery(this).val() == 1) {
				getURL('/media-services/showcase/sort/all-creative');
			} else if (jQuery(this).val() == 2) {
				getURL('/media-services/showcase/sort/high-impact');
			} else {
				jQuery('#creative_sort').val("0");
			}
			jQuery('#creative_type').remove();
		}
	});



  function getCategoryNames(e){
	jQuery.getJSON("/_inc/campaign_sort.php",{id: jQuery(e).val(), ajax: 'true'}, function(j){
	var options = '';
	for (var i = 0; i < j.length; i++) {
		options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
	}
	//jQuery("img").insertAfter('#creative_type');
	jQuery(".x_menLoader").fadeOut('fast');
	jQuery("#creative_type").html(options).fadeIn("slow", function(){jQuery(this).focus()});
	});
  }
};

jQuery.centro.highlightCampaign = function(){
      jQuery('.campaign_row').hover(function() {
		jQuery(this).addClass('hover');
      }, function() {
        jQuery(this).removeClass('hover');
      });

	  jQuery('.campaign_row').click(function(){
		var newWindow = window.open(jQuery(this).find('.campaign_link').attr('href'), '_blank');
		newWindow.focus();
		return false;
	  });

	  jQuery("table.campaign_matrix tr:even").addClass("oddrow");
};

// NEWS
jQuery.centro.showFeeds = function() {
	jQuery('.news_feeds').hide();
	jQuery(".available_feeds .icon_rss").click(function() {
		jQuery('.news_feeds').slideToggle(400);
		return false;
	});
};


// EVENTS
jQuery.centro.clickEventBox = function() {
	jQuery(".events_box").click(function() {
		getURL(jQuery(this).find('a').attr('href'));
	});
};

jQuery.centro.hideWarning = function() {
	jQuery('.x_jsReq').hide();
};


// CAREERS
jQuery.centro.prepCareer= function() {
	jQuery('.frmSubmit').before('<a href="#" class="c_next">Login</a>').remove();
	jQuery('.c_next').click(function(){
		jQuery('#frmLogin').submit();
	});
};

// CONTACT
jQuery.centro.prepContact= function() {

	jQuery('#how').val(0);
	jQuery('.input_other').hide();
	jQuery('#other').attr("value","");
	jQuery("#how").change(function() {
		if(jQuery(this).val() == 'Other: Specify') {
			jQuery('.input_other').fadeIn("slow");
		} else {
			jQuery('.input_other').fadeOut("slow", function(){jQuery('#other').attr("value","");});
		}
	});
};

// MEDIA SERVICES
jQuery.centro.prepFilmStrip = function(){
	jQuery(".filmstrip_slide").jCarouselLite({
		btnNext: ".filmstrip .next",
		btnPrev: ".filmstrip .prev",
		scroll: 5,
		visible: 5
	});

	jQuery('.filmstrip a.prev').show();
	jQuery('.filmstrip a.next').show();
};

jQuery.centro.prepFilmStripSide = function(){
	jQuery(".testimonials_slide").jCarouselLite({
		btnNext: ".filmstrip_testimonials .next_sm",
		btnPrev: ".filmstrip_testimonials .prev_sm",
		visible: 1
	});

	jQuery(".showcase_slide").jCarouselLite({
		btnNext: ".filmstrip_showcase .next_sm",
		btnPrev: ".filmstrip_showcase .prev_sm",
		visible: 1
	});

	jQuery('.filmstrip_testimonials a.prev_sm').show();
	jQuery('.filmstrip_testimonials a.next_sm').show();

	jQuery('.filmstrip_showcase a.prev_sm').show();
	jQuery('.filmstrip_showcase a.next_sm').show();


};

//Centro Creative
jQuery.centro.centroCreative = function(page,wid){
  jQuery("#creative_sort").change(function(){
		if(jQuery(this).val() > 2) {
			// create new select if it doesn't exist
			if(jQuery('#creative_type').length === 0){
				jQuery(".x_menLoader").fadeIn('slow');
				jQuery('<select id="creative_type"></select>').hide().insertAfter('#creative_sort');
				jQuery("#creative_type").change(function(){
					getURL('/'+page+'/sort/' + jQuery(this).val());
				});
			}
			getCategoryNames(this,wid);

		} else {
			if (jQuery(this).val() == 1) {
				getURL('/'+page+'/sort/all-creative');
			}
			jQuery('#creative_type').remove();
		}
	});

  function getCategoryNames(e,wid){
		jQuery.getJSON("/_inc/campaign_sort.php",{id:jQuery(e).val(), 'wid':wid, ajax:'true'}, function(j) {
			var options = '';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			//jQuery("img").insertAfter('#creative_type');
			jQuery(".x_menLoader").fadeOut('fast');
			jQuery("#creative_type").html(options).fadeIn("slow", function(){jQuery(this).focus()});
		});
  }
};
