/*
 * ukstudy.com JavaScript Library
 * @category   UKStudy
 * @copyright  Copyright (c) 2008-2009 UKStudy
 * @version    0.1
 * @author     Davood Firozian, Ramin Siahcheshmi
 * @license    
*/

if (typeof(ukstudy) == "undefined") 
	ukstudy = function () {}
	
ukstudy.updateRegionCitys = function(region) {
      var options = '<option value="0" echo "selected" >All</option>';
      for (var i = 0; i < ukstudy.regionCities.length; i++) {
      	if (ukstudy.regionCities[i].region_id == region )
        	options += '<option value="' + ukstudy.regionCities[i].town_id + '" >' +
        		ukstudy.regionCities[i].lang_town + '</option>';
      }
      $("select#fs_town").html(options);
}

ukstudy.getRegionCities = function( moduleId ) {
	$.getJSON("/" + context.lang + "/single:" + moduleId.toString(),{information_search_action: 'get_towns'}, function(j){
		ukstudy.regionCities = j;
	})
}

/**
 * Javascript Transitions (Collapse & Expand) for Panels in website
 *
 * collapsible panel in course, School and town pages
 *
 * @param panelClass Panel to be collapsed/Expanded 
 * @todo  This function can be created using jQuery Plugins .., But its enough for now
 *
 */
ukstudy.initCollapsiblePanel = function (panelClass) {
	$(function() {
		$(panelClass + ' > div:nth-child(2)').css({'display': 'none'});
		$header      = $('.switch:not(.switch:first)');
		$mainHeader = $('.switch');
		toggleMinus  = '/images/general/panel/arrow_top.gif';
	  	togglePlus   = '/images/general/panel/arrow_bot.gif';
	
		$('.switch:first').prepend('<img src="' + toggleMinus + '"alt="collapse this section" />')
			.parents('DIV').parents('DIV').siblings('.cpm').slideDown();	
		$header.prepend('<img src="' + togglePlus + '"alt="collapse this section" />');
		$('img', $mainHeader).click(function() {
			var toggleSrc = $(this).attr('src');
			if ( toggleSrc == toggleMinus ) {
				$(this).attr('src', togglePlus).parents('DIV').parents('DIV').siblings('.cpm').slideUp();
			} else{
				$(this).attr('src', toggleMinus).parents('DIV').parents('DIV').siblings('.cpm').slideDown();
	    	};
		});
		$('.cpTitle').css('cursor','pointer').click(function() {
			var toggleSrc = $('img',$(this).siblings()).attr('src');
			if ( toggleSrc == toggleMinus ) {
				$('img',$(this).siblings()).attr('src', togglePlus);
				$(this).parents('DIV').parents('DIV').siblings('.cpm').slideUp();
			} else{
				$('img',$(this).siblings()).attr('src', toggleMinus);
				$(this).parents('DIV').parents('DIV').siblings('.cpm').slideDown();
	    	};
		});
		
	})
}

 /*
 * VISA section collapse expand
 *
 * @param visaInfo Panel to be collapsed/Expanded
 */
ukstudy.initVisa = function(visaInfo) {
	$(function() {
		toggleMinus    = '/images/general/arrow_top.gif';
		togglePlus     = '/images/general/arrow_bot.gif';
		
		$(visaInfo + ' > li > div:first-child').siblings().css('display', 'none')
			.end().prepend('<img src="' + toggleMinus + '">');
		
		$(visaInfo + ' > li > div:nth-child(2) a').css('color', '#ed2c20');
		$expandedBlock = null;
		$(visaInfo + ' > li > div:first-child').click(function() {
			if($expandedBlock) {
				$expandedBlock.siblings().slideUp();
				$('img', $expandedBlock).attr('src', toggleMinus);
			}
			$(this).siblings().css({'padding-left':'15px'}).slideDown();
			$('img', $(this)).attr('src', togglePlus);
			$expandedBlock = $(this);
		});
		$('#visa-expand').prepend('<img src="/images/general/plus.gif">').css('cursor', 'pointer').click(function() {
			$('ul > li > div:first-child').siblings().css({'padding-left':'15px'}).slideDown();
			$('img', $('.visa-info > li > div:first-child')).attr('src',togglePlus);
		});
	
		$('#visa-collapse').prepend('<img src="/images/general/minus.gif">').css('cursor', 'pointer').click(function() {
			$('ul > li > div:first-child').siblings().slideUp();
			$('img', $('.visa-info > li > div:first-child')).attr('src',toggleMinus);
		});
	})
}