/* For Image Gallery	 */
$(document).ready(function(){
	toggle_language(); // Add click function to language select element
	initWeather();
	loadAjax();
	loadAds();
});

function toggle_language() {
	// Check if cookie already exists
	var currentLang = new String($(".languageSelect").find("li.selected > a").attr('class'));
	var cookieLang = $.cookie('lang');
	//alert("currentLang : " + currentLang + "cookieLang: " + cookieLang));
	if (currentLang != 'undefined' && (cookieLang == null || cookieLang.indexOf(currentLang) == -1)) {
		if ((currentLang.indexOf("ar") != -1)) {
			$.cookie('lang', 'ar_AE', { path: '/' });
			//alert("Setting default lang to ARABIC");
		} else if ((currentLang.indexOf("en") != -1)) {
			$.cookie('lang', 'en_GB', { path: '/' });
			//alert("Setting default lagn to ENGLISH");
		}
	}

	$('.ar_language').click(function(e) {
		$.cookie('lang', 'ar_AE', { path: '/' });
	});

	$('.en_language').click(function(e) {
		$.cookie('lang', 'en_GB', { path: '/' });
	});
}

 function loadAds() {
   	jQuery('.ad').each(function() {
        var element = this;
        jQuery(element).find("iframe").css("display", "block");
        // do something with element
        /*
        var cssClass = jQuery(element).attr('class');

        var classes = cssClass.split(" ");
        var value = classes[1];
        if (typeof value != 'undefined') {
        	var params = value.split("-"); //format is site-widht-height
        	if (params.length == 3) {
        		var category = params[0];
        		var width = params[1];
        		var height = params[2];

   				var url = jQuery(element).find("input:first").attr('value');
   				jQuery(element).append("<iframe src=\""+ url + "\" width=\""+ width + "\" height=\"" + height + "\" frameborder=\"0\" scrolling=\"no\/>");
   			}
        }*/
    });
}

function loadAjax() {
   	jQuery('.ajax').each(function() {
   		var element = this;
   		var url = jQuery(element).find("input:first").attr('value');
   		jQuery.get(url, function(data) {
                             jQuery(element).html(data);
                             jQuery(element).removeClass('ajax');
                       });
   	});
}

function initWeather() {
	jQuery("#wForm").submit(function() {
		var formAction = jQuery("#wForm").attr("action");
		formAction += jQuery("#wCities option:selected").attr("value");
		jQuery("#wForm").attr("action", formAction);
      	return true;
    });

	jQuery("#wCountry").change(function() {
		    var url = jQuery("#wUrl").attr("value");

			jQuery.getJSON(url, { "view" : "data", "cy" : jQuery("#wCountry option:selected").attr("value")},
            function(data, textStatus){
			  if("success" == textStatus) {
    			  var options = '';
                  jQuery.each(data, function(i,item){
                    options += '<option value="' + item.value + '">' + item.label + '<\/option>';
    			  }); // End loop
				  jQuery("#wCities").html(options);
			  }
            }); // End json get
       }); // End change
}

/**
 *
 */
function initVideoPlayer(containerId, imageUrl, videoUrl) {
	//alert("initVideoPlayer('" + containerId + "', '" + imageUrl + "', '" + videoUrl + "'");
	// the splash image
	image = {
		url: imageUrl,
		scaling:  'fit'
	};
	// the video. when autoPlay is set to false the splash screen will be shown
	video = {
		url: videoUrl,
		autoPlay: false
	};

	//  install Flowplayer
	$f(containerId, '/res/swf/flowplayer/flowplayer-3.1.5.swf',
		{
			// here is our playlist with two clips
			playlist: [ image, video ],
			// screen positioning inside "Hello world" screen.
			screen: {
				width: 320/*,*/
				/*height: 225*/
			},
			canvas: {backgroundColor: "#999999"},
			plugins: {
				controls: {
					// styling properties
					height: 24,
					opacity: 1.0,
					background: '#EEEEEE',
					backgroundGradient: 'low',
					backgroundColor: '#999999',

					all: false,
					play: true,
					scrubber: true,
					volume: true,
					fullscreen: true,

					// Color of the progress bar
					progressColor: '#D2232A',
					// Gradient setting for the progress bar
					progressGradient: 'medium',
					// Color of the buffer
					bufferColor: '#666666',
					// Gradient setting for the buffer. See below for its valid values
					bufferGradient: 'none',
					// Background color for the timeline before the buffer bar fills it
					sliderColor: '#000000',
					// Gradient setting for the sliders
					sliderGradient: 'none',
					// Color of the player buttons
					buttonColor: '#000000',
					// Button color when the mouse is positioned over them
					buttonOverColor: '#D2232A',
					// Background color for the volume slider (since 3.1)
					volumeSliderColor: '#000000',
					// Volume slider background color gradient (since 3.1).
					volumeSliderGradient: 'none',

					borderRadius: '10px',

					tooltipColor: '#000000',
					tooltipTextColor: '#ffffff',
					// tooltips (since 3.1)
					tooltips: 'null'
				}
			}
		}
	);
}

