﻿if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelectorAll('meta[name="viewport"]')[0];
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
document.body.addEventListener('gesturestart', function() {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}


var loadAfterAjax = function() {
	
	// Scroller
	$('.scroll-pane').jScrollPane();
	
	// Slider
    jQuery(".pagination-wrapper").sliderkit({
        auto:false,
        tabs:true,
        freeheight:true,
		scrolleasing:"easeOutExpo"
    });
	
	var TotalPagesCount_1, TotalPagesCount_2, TotalPagesCount_3, TotalPagesCount_4;
	var TotalDisplayCount_1, TotalDisplayCount_2, TotalDisplayCount_3, TotalDisplayCount_4;
	
	TotalPagesCount_1 = $('#pagination-item-counter-1').html();
	
	if (TotalPagesCount_1 > 10){
		TotalDisplayCount_1 = 10;
		
		$("#pagination").paginate({
			count 		: TotalPagesCount_1,
			start 		: 1,
			display     : TotalDisplayCount_1,
			border					: true,
			border_color			: '#fff',
			text_color  			: '#fff',
			background_color    	: '#1780D3',	
			border_hover_color		: '#fff',
			text_hover_color  		: '#fff',
			background_hover_color	: '#000', 
			images					: false,
			mouse					: 'press',
			onChange     			: function(page){
										var clickedButton = $('.jPag-current').text();
										$('.sliderkit-nav-clip').find('a[href$="#'+ clickedButton +'"]').trigger('click');
									}
		});
	
	}
	else{
		$('#pagination-old-1').show();
	}
	
	TotalPagesCount_2 = $('#pagination-item-counter-2').html();
	
	if (TotalPagesCount_2 > 10){
		TotalDisplayCount_2 = 10;
		
		$("#pagination2").paginate({
			count 		: TotalPagesCount_2,
			start 		: 1,
			display     : TotalDisplayCount_2,
			border					: true,
			border_color			: '#fff',
			text_color  			: '#fff',
			background_color    	: '#1780D3',	
			border_hover_color		: '#fff',
			text_hover_color  		: '#fff',
			background_hover_color	: '#000', 
			images					: false,
			mouse					: 'press',
			onChange     			: function(page){
										var clickedButton = $('.jPag-current').text();
										$('.sliderkit-nav-clip').find('a[href$="#'+ clickedButton +'"]').trigger('click');
									}
		});
	
	}
	else{
		$('#pagination-old-2').show();
	}
	
	TotalPagesCount_3 = $('#pagination-item-counter-3').html();
	
	if (TotalPagesCount_3 > 10){
		TotalDisplayCount_3 = 10;
		
		$("#pagination3").paginate({
			count 		: TotalPagesCount_3,
			start 		: 1,
			display     : TotalDisplayCount_3,
			border					: true,
			border_color			: '#fff',
			text_color  			: '#fff',
			background_color    	: '#1780D3',	
			border_hover_color		: '#fff',
			text_hover_color  		: '#fff',
			background_hover_color	: '#000', 
			images					: false,
			mouse					: 'press',
			onChange     			: function(page){
										var clickedButton = $('.jPag-current').text();
										$('.sliderkit-nav-clip').find('a[href$="#'+ clickedButton +'"]').trigger('click');
									}
		});
	
	}
	else{
		$('#pagination-old-3').show();
	}
	
	TotalPagesCount_4 = $('#pagination-item-counter-4').html();
	
	if (TotalPagesCount_4 > 10){
		TotalDisplayCount_4 = 10;
		
		$("#pagination4").paginate({
			count 		: TotalPagesCount_4,
			start 		: 1,
			display     : TotalDisplayCount_4,
			border					: true,
			border_color			: '#fff',
			text_color  			: '#fff',
			background_color    	: '#1780D3',	
			border_hover_color		: '#fff',
			text_hover_color  		: '#fff',
			background_hover_color	: '#000', 
			images					: false,
			mouse					: 'press',
			onChange     			: function(page){
										var clickedButton = $('.jPag-current').text();
										$('.sliderkit-nav-clip').find('a[href$="#'+ clickedButton +'"]').trigger('click');
									}
		});
	
	}
	else{
		$('#pagination-old-4').show();
	}
	
    // Fancybox
    $(".gallery li a").fancybox({
		overlayColor: '#000'
	});
	$("a.lightbox").fancybox({
		overlayColor: '#000'
	});
	
	//highlights the current in a menu by comparing the links to the current URL path
    var links = $('.bbq-nav').find('a');
	var linkFound = false;
	
    links.each(function () {
		
        if (window.location.hash.indexOf($(this).attr("href")) != -1) {
			$('.bbq-nav').find('a').removeClass("active");
			$('.bbq-nav li:first-child a').removeClass("active");
            $(this).addClass("active");
			linkFound = true;
        }
		else {
			if (!linkFound ) {
				if (window.location.hash.indexOf('all-originals-news') != -1) {
					$("a[rel^='alloriginals']").addClass("active");
				}
				else{
					$('.bbq-nav li:first-child a').addClass("active");
				}
			}
			else{
				if (window.location.hash.indexOf('all-originals-news') != -1) {
					$("a[rel^='alloriginals']").addClass("active");
					$("a[rel^='home']").removeClass("active");
				}
			}
		}
		
    });
	
	window.fbAsyncInit = function() {
		FB.init({appId: '223431834340177', status: true, cookie: true, xfbml: true});
		FB.XFBML.parse();
	};

	
	/*
	var detail_1 = $('div#page-details-1').html();
	var detail_3 = $('div#page-details-3').html();
	var detail_4 = $('div#page-details-4').html();
	var detail_6 = $('div#page-details-6').html();

	$('meta#meta_1').attr('content',detail_1);
	$('meta#meta_3').attr('content',detail_3);
	$('meta#meta_4').attr('content',detail_4);
	$('meta#meta_6').attr('content',detail_6);
	*/
}

$(function(){

	var PlayerCounter = 0;
	
	/*
	$('a.jp-play').click(function() {
		$("#jquery_jplayer_1").jPlayer("destroy");
	});
	
	$('a.jp-play').click(function() {
		if (PlayerCounter >= 2)
			$("#jquery_jplayer_1").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://217.20.112.150:3442"
					}).jPlayer("play");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "js",
				supplied: "mp3"
			});
		}
	});
	*/
	
	// External Links
	$("a[rel^='external']").each(
		function(){
			$(this).attr('target', '_blank').addClass('external');
		}
	);
	
	
	//var meta = document.createElement('meta');
	//meta.name = 'og:title';
	//meta.content = 'title sdf dgfsfg sgsdgf sdgf';
	//document.getElementsByTagName('head')[0].appendChild(meta);
	
	
	// History Support
    $('.bbq-nav a').each(function(){
        var rel = $(this).attr('rel');
        var nice = $(this).attr('href');
        if( rel === 'home' )
            $(this).attr('href','#');
        else
            $(this).attr('href','#/' + nice);
    });
    
    // Keep a mapping of url-to-container for caching purposes.
    var cache = {
        // If url is '' (no fragment), display this div's content.
        '': $('.bbq-default')
    };
    
    // Bind an event to window.onhashchange that, when the history state changes,
    // gets the url from the hash and displays either our cached content or fetches
    // new content to be displayed.
    $(window).bind('hashchange', function(e) {
		
		// External Links
		$("a[rel^='external']").each(
			function(){
				$(this).attr('target', '_blank').addClass('external');
			}
		);
		
        // Get the hash (fragment) as a string, with any leading # removed. Note that
        // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
        var url = $.param.fragment();
        
        // Remove .active class from any previously "current" link(s).
        $('a.active').removeClass( 'active' );
		
		//if (url.indexOf('all-originals-news') != -1) {
		//	url = url.replace('all-originals-news','all-originals');
        //}

        // Hide any visible ajax content.
        $( '.bbq-content' ).children( ':visible' ).hide();
        // Add .active class to "current" nav link(s), only if url isn't empty.
        url && $( 'a[href="#' + url + '"]' ).addClass( 'active' );
        
        if ( cache[ url ] ) {
			// Since the element is already in the cache, it doesn't need to be
			// created, so instead of creating it again, let's just show it!
			cache[ url ].show();
			if (url == ""){
				$('.bbq-nav li:first-child a').addClass("active");
			}
        
        } else {
        // Show "loading" content while AJAX content loads.
        $( '.bbq-loading' ).show();
        
        // Create container for this url's content and store a reference to it in
        // the cache.
        cache[ url ] = $( '<div class="bbq-item"/>' )
            
            // Append the content container to the parent container.
            .appendTo( '.bbq-content' )
            
            // Load external content via AJAX. Note that in order to keep this
            // example streamlined, only the content in .infobox is shown. You'll
            // want to change this based on your needs.
            .load( url, function(){
            // Content loaded, hide "loading" content.
                $('.bbq-loading').hide();
                $('html, body').animate({scrollTop:0}, 'slow');
                loadAfterAjax();
            });
        }
    })
    
    // Since the event is only triggered when the hash changes, we need to trigger
    // the event now, to handle the hash the page may have loaded with.
    $(window).trigger( 'hashchange' );
	$("a[rel^='home']").live('click', function(event) {
			$(this).addClass("active");
	});

    // Player
    $("#jquery_jplayer_1").jPlayer({
        ready: function () {
			PlayerCounter = PlayerCounter + 1;
            $(this).jPlayer("setMedia", {
				mp3: "http://78.159.112.254:9370/;stream.nsv"
            }).jPlayer("play");
        },
        ended: function (event) {
            $(this).jPlayer("play");
        },
        swfPath: "js",
        supplied: "mp3"
    });
	
	// Scroll to top of content
	$('.jPag-pages').closest('a').live('click', function() {
		alert('csdcd');
	});
    
});


jQuery(function($){
	$.supersized({
		start_slide				:	0,		//Start slide (0 is random) //Requires multiple background images
		slideshow               :   1,		//Slideshow on/off
		autoplay				:	1,		//Slideshow starts playing automatically
		vertical_center         :   1,		//Vertically center background
		horizontal_center       :   1,		//Horizontally center background
		min_width		        :   0,		//Min width allowed (in pixels)
		min_height		        :   0,		//Min height allowed (in pixels)
		fit_portrait         	:   0,		//Portrait images will not exceed browser height
		fit_landscape			:   0,		//Landscape images will not exceed browser width
		slides					:   [ 		//Background image
									  		{ image : '/img/theme/originals1.jpg' },
									  		{ image : '/img/theme/originals2.jpg' },
									  		{ image : '/img/theme/originals3.jpg' },
											{ image : '/img/theme/originals4.jpg' },
											{ image : '/img/theme/originals5.jpg' },
											{ image : '/img/theme/originals6.jpg' },
											{ image : '/img/theme/originals7.jpg' },
											{ image : '/img/theme/originals8.jpg' },
											{ image : '/img/theme/originals9.jpg' },
											{ image : '/img/theme/originals10.jpg' },
											{ image : '/img/theme/originals11.jpg' },
											{ image : '/img/theme/originals12.jpg' },
											{ image : '/img/theme/originals13.jpg' },
											{ image : '/img/theme/originals14.jpg' },
											{ image : '/img/theme/originals15.jpg' }
									]					
	});
});

jQuery(window).load(function(){ //jQuery(window).load() must be used instead of jQuery(document).ready() because of Webkit compatibility				
	
	loadAfterAjax();
    
    $('#featured').orbit({
        captions: true
    });
	
});


$("#site-search-form").live('submit',function(event){
    event.preventDefault();
	var searchword = $('#site-search-keyword').val();
	
	if (searchword == "" || searchword == "Arama")
	{
		return false;
	}
    //console.dir(event);
    //var url = $.bbq.getState( "url" );
	//var postURL = 'http://radioadidasoriginals.com/#/search?q=' + searchword;
	var postURL = 'http://www.radioadidasoriginals.com/#/search?q=' + searchword;
	location.href = postURL;
	/*
	$.ajax({
		cache:false,
		async:false,
		type: "GET",
		data: "q=" + $('#site-search-keyword').val(),
		url: postURL,
		success: function(data) {
			$('.main').html(data);
			//$.bbq.pushState({ search: searchword }, 0);
			/*
            var href = 'q='+ $('#site-search-keyword').val() +'';
            var url = 'http://radioadidasoriginals.com/#/search'
			url = url.replace( /^#/, '' );
			alert(url);
			state[ id ] = url;
            //$.bbq.pushState({ url : href });
            //console.dir(data);
            console.log("loaded new page");
            alert('Load was performed.');
            bindFunc();
		}
	});
	
	/*
    $.ajax({
        url: url,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            error = true;
            alert("communication error");
            //handler(XMLHttpRequest.responseText,error);
        },
        type: "POST",
        data: $("form#site-search-form").serialize(),
        dataType: "json",
        processData: false,
        success: function(data, textStatus, XMLHttpRequest) {
		alert('aa')
            $('.content').html(data.html);
            var href = data.address;
            var url = $.bbq.getState( "url" );
            $.bbq.pushState({ url : href });
            //console.dir(data);
            console.log("loaded new page");
            //alert('Load was performed.');
            bindFunc();     
        }
    });
	*/
});


$("#Newsletter-Subscriber").live('submit',function(event){
	$.ajax({
		type		: "POST",
		cache		: false,
		url			: "http://www.radioadidasoriginals.com/subscribe-newsletter",
		data		: $(this).serializeArray(),
		success: function(data) {
			$('#form-message').html(data);
			$('#form-message').show();
			setTimeout(function(){$('#form-message').hide();},6000);
		}
	});
	
	return false;
});


$("form#ContactForm").live("submit", function(event) {

	var cvalidEmail;
	if ($('#ContactEmail').val() != ""){
		var cpattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		cvalidEmail = cpattern.test($('#ContactEmail').val());
	}
	if (cvalidEmail == false ) {
		$("#contact_error").removeClass("hidden").html("Lütfen geçerli bir e-mail adresi girin.");
		//$.fancybox.resize();
		return false;
	}
	else if ($("#ContactName").val().length < 1 || $("#ContactEmail").val().length < 1) {
		$("#contact_error").removeClass("hidden").html("Lütfen tüm alanları doldurun.");
		//$.fancybox.resize();
		return false;
	}
	
	$("#contact_error").addClass('hidden');
	$.fancybox.showActivity();

	$.ajax({
		type		: "POST",
		cache		: false,
		url			: "http://www.radioadidasoriginals.com/share-music-email", 
		data		: $(this).serializeArray(),
		success		: function(data) {
			$.fancybox(data);
		}
	});

	return false;
});
